Can't get Animated.event to work in WebView onScroll
See original GitHub issueCurrently trying to implement simple transform of view using Reanimated. I have a View(like header) above webview, and I’m trying to move this view while scrolling. Code is as follows:
const y = new Animated.Value(0);
const AnimatedWebView = Animated.createAnimatedComponent(WebView);
function WebPage() {
return (
<SafeAreaView style={{flex: 1}}>
<Animated.View
style={{
height: 60,
width: '100%',
backgroundColor: 'lightblue',
transform: [{translateY: y}],
}}
/>
<AnimatedWebView
source={{
uri: 'https://www.stackoverflow.com',
}}
originWhitelist={['*']}
onScroll={Animated.event([{nativeEvent: {contentOffset: {y: y}}}])}
/>
</SafeAreaView>
);
}
Above doesn’t trigger any transform, so I’ve tried this with normal scrollview. Everything same except scrollview component:
const y = new Animated.Value(0);
const AnimatedWebView = Animated.createAnimatedComponent(WebView);
function WebPage() {
return (
<SafeAreaView style={{flex: 1}}>
<Animated.View
style={{
height: 60,
width: '100%',
backgroundColor: 'lightblue',
transform: [{translateY: y}],
}}
/>
<Animated.ScrollView
style={
{
marginHorizontal: 20,
}
}
scrollEventThrottle={16}
onScroll={Animated.event([{nativeEvent: {contentOffset: {y: y}}}])}>
<Text
style={{
fontSize: 42,
}}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</Text>
</Animated.ScrollView>
</SafeAreaView>
);
}
this works fine. Am I doing something wrong, or is this a bug?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (4 by maintainers)
Top Results From Across the Web
$(window).scroll event not triggered in android WebView
In android app I have webView page that use jquery plugin for lazyload. In mobile browser it work fine but not in webView....
Read more >[Solved]-How does Animated.Event work in React Native?
Coding example for the question How does Animated.Event work in React Native?-React Native.
Read more >Document: scroll event - Web APIs - MDN Web Docs - Mozilla
The scroll event fires when the document view has been scrolled. To detect when scrolling has completed, see the Document: scrollend event.
Read more >Reveal or hide a view using animation - Android Developers
Retrieve and cache the system's default "short" animation time. shortAnimationDuration = resources.getInteger(android.
Read more >Rendered area of WKWebView while s… - Apple Developer
__auto_type animation = ^{ self.webView.scrollView.contentOffset = CGPointZero; }; [UIView animateWithDuration:0.3 delay:0.0 options: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yup, I solved it for LinguaBrowse. It only takes a very minor change to add Animated support to React Native Webview, but my PR (https://github.com/react-native-community/react-native-webview/pull/1102) never got merged and sadly upstream has moved on vastly since then (e.g. addition of Windows and macOS platforms).
Would be glad if someone else could pick it up. It’s just a one-line change required for each platform implementation, followed by a bunch of adding documentation.
Warning: Don’t expect that adding this change alone would bring Animated scroll support to macOS Cocoa, because macOS Cocoa’s WKWebView is limited in another aspect in that its WKWebView (unlike iOS) lacks a UIScrollView altogether (and thus fires no scroll event at all). You could pass the DOM “scroll” events up from the webpage if you really wanted it for macOS Cocoa too, but I’d call that a separate PR.
(I haven’t checked whether anyone’s implemented it yet, but I doubt it).
If I understand this correctly this is related to forwarding refs to the underlying animated component. Forwarding refs was fixed in 1.10.0, so I’m going to close this one now. I’m open for discussion though.