Skip to content

Commit 514dadb

Browse files
committed
StoryScreen: keep WebView mounted across tab switches to preserve navigation state
1 parent 7089f81 commit 514dadb

1 file changed

Lines changed: 56 additions & 60 deletions

File tree

screens/StoryScreen.jsx

Lines changed: 56 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,6 @@ export default function StoryScreen() {
390390
setTabView(tab);
391391
}, [tab]);
392392

393-
const webMounted = tabView === 'web';
394-
395393
const initialScrollY = useStore((state) => state.storyScroll?.get?.(id) || 0);
396394
const scrollY = useRef(initialScrollY);
397395
const setStoryScroll = useStore((state) => state.setStoryScroll);
@@ -641,70 +639,69 @@ export default function StoryScreen() {
641639
],
642640
}}
643641
>
644-
{webMounted && (
645-
<WebView
646-
ref={webViewRef}
647-
style={{ backgroundColor: colors.background }}
648-
applicationNameForUserAgent={`${Application.applicationName}/${Application.nativeApplicationVersion}`}
649-
source={{ uri: url }}
650-
originWhitelist={[
651-
'http://*',
652-
'https://*',
653-
'data:*',
654-
'about:*',
655-
]}
656-
decelerationRate="normal"
657-
allowsInlineMediaPlayback
658-
contentInsetAdjustmentBehavior="automatic"
659-
automaticallyAdjustContentInsets
660-
automaticallyAdjustsScrollIndicatorInsets
661-
allowsBackForwardNavigationGestures
662-
renderLoading={() => null}
663-
onNavigationStateChange={(navState) => {
664-
setNavState(navState);
665-
}}
666-
onLoadStart={() => {
667-
progressAnim.setValue(0);
668-
progressOpacityAnim.setValue(1);
669-
addLink(url);
670-
}}
671-
onLoadEnd={() => {
672-
Animated.timing(progressAnim, {
673-
toValue: 1,
642+
<WebView
643+
ref={webViewRef}
644+
style={{ backgroundColor: colors.background }}
645+
applicationNameForUserAgent={`${Application.applicationName}/${Application.nativeApplicationVersion}`}
646+
source={{ uri: url }}
647+
originWhitelist={[
648+
'http://*',
649+
'https://*',
650+
'data:*',
651+
'about:*',
652+
]}
653+
decelerationRate="normal"
654+
allowsInlineMediaPlayback
655+
contentInsetAdjustmentBehavior="automatic"
656+
automaticallyAdjustContentInsets
657+
automaticallyAdjustsScrollIndicatorInsets
658+
allowsBackForwardNavigationGestures
659+
renderLoading={() => null}
660+
onNavigationStateChange={(navState) => {
661+
setNavState(navState);
662+
}}
663+
onLoadStart={() => {
664+
progressAnim.setValue(0);
665+
progressOpacityAnim.setValue(1);
666+
addLink(url);
667+
}}
668+
onLoadEnd={() => {
669+
Animated.timing(progressAnim, {
670+
toValue: 1,
671+
duration: 300,
672+
useNativeDriver: false,
673+
}).start(() => {
674+
Animated.timing(progressOpacityAnim, {
675+
toValue: 0,
676+
delay: 100,
674677
duration: 300,
675678
useNativeDriver: false,
676-
}).start(() => {
679+
}).start();
680+
});
681+
}}
682+
onLoadProgress={(e) => {
683+
const { progress, loading } = e.nativeEvent;
684+
Animated.timing(progressAnim, {
685+
toValue: progress,
686+
duration: 1000,
687+
useNativeDriver: false,
688+
}).start(() => {
689+
if (progress > 0.99) {
677690
Animated.timing(progressOpacityAnim, {
678691
toValue: 0,
679692
delay: 100,
680693
duration: 300,
681694
useNativeDriver: false,
682695
}).start();
683-
});
684-
}}
685-
onLoadProgress={(e) => {
686-
const { progress, loading } = e.nativeEvent;
687-
Animated.timing(progressAnim, {
688-
toValue: progress,
689-
duration: 1000,
690-
useNativeDriver: false,
691-
}).start(() => {
692-
if (progress > 0.99) {
693-
Animated.timing(progressOpacityAnim, {
694-
toValue: 0,
695-
delay: 100,
696-
duration: 300,
697-
useNativeDriver: false,
698-
}).start();
699-
}
700-
});
701-
setNavState({
702-
...navState,
703-
loading,
704-
});
705-
}}
706-
onMessage={() => {}}
707-
injectedJavaScript={`
696+
}
697+
});
698+
setNavState({
699+
...navState,
700+
loading,
701+
});
702+
}}
703+
onMessage={() => {}}
704+
injectedJavaScript={`
708705
try {
709706
document.querySelectorAll('video[autoplay]').forEach(v => v.playsInline = true);
710707
var observer = new MutationObserver(function(mutations) {
@@ -714,8 +711,7 @@ export default function StoryScreen() {
714711
} catch (e) {}
715712
true;
716713
`}
717-
/>
718-
)}
714+
/>
719715
</Animated.View>
720716
<ScrollView
721717
pointerEvents="none"

0 commit comments

Comments
 (0)