Repository navigation
Description
Description
After using useNativeDriver transform button, finger movement occurs when the button is pressed, the button's onPress will not be called, but the visual feedback of the button is normal.
The bug only occurs on Android devices, and when the new architecture is enabled, useNativeDriver=true is set.
React Native Version
0.71.4
Output of npx react-native info
System:
OS: macOS 13.1
CPU: (10) arm64 Apple M1 Pro
Memory: 148.16 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 19.7.0 - /opt/homebrew/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 9.5.0 - /opt/homebrew/bin/npm
Watchman: 2023.03.06.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: Not Found
SDKs:
iOS SDK:
Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
Android SDK:
API Levels: 28, 29, 30, 31, 32, 33
Build Tools: 28.0.3, 30.0.2, 30.0.3, 31.0.0, 33.0.0
System Images: android-31 | Google APIs ARM 64 v8a, android-33 | Google APIs ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: Electric Eel 2022.1.1 Patch 2 Electric Eel 2022.1.1 Patch 2
Xcode: 14.2/14C18 - /usr/bin/xcodebuild
Languages:
Java: 11.0.15 - /opt/homebrew/opt/openjdk@11/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.4 => 0.71.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
Run my code, Press the button after scrolling the FlatList, move your finger slightly and lift it up.
Snack, code example, screenshot, or link to a repository
import React, {useRef, useState} from 'react';
import {View, Text, Button, Animated} from 'react-native';
const componentList: number[] = Array.from(new Array(100).keys());
const App = () => {
const currScroll = useRef(new Animated.Value(0)).current;
const [count, setCount] = useState(0);
return (
<View style={{flex: 1}}>
<Animated.View
style={{
position: 'absolute',
zIndex: 2,
width: '100%',
transform: [{translateY: currScroll}],
}}>
<Button
title={Press count : ${count}}
onPress={() => {
console.log('pressed');
setCount(count + 1);
}}>
</Animated.View>
<Animated.FlatList
style={{width: '100%', height: '100%', position: 'absolute', zIndex: 1}}
data={componentList}
renderItem={({index}) => (
<Text
style={{
backgroundColor: 'white',
height: 28,
}}>
{index}
)}
keyExtractor={item => item.toString()}
onScroll={Animated.event(
[
{
nativeEvent: {
contentOffset: {
y: currScroll,
},
},
},
],
{useNativeDriver: true},
)}></Animated.FlatList>
);
};
export default App;
Activity
iMonk777 commentedon May 5, 2023
Hi @ThinkerLu , we still have this issue. Did you find any solution for this?
jugshaurya commentedon May 29, 2023
+1, after applying transform: translateX/Y/Z(*), on Animated.View, internal content of this View become non-responsive, works after multiple clicking.
It comes after using New Arch.Even used latest 0.72.0-RC.3
Tested Today: 29/05/23
skinsapp commentedon Jun 11, 2023
@jugshaurya I can confirm I'm having the same issue, using 71.10, android. It basically makes the new architecture unusable on Android, unless you plan to have no animation. It's occurring with all touchables and pressables.
related: #36710
jugshaurya commentedon Jun 11, 2023
I found a temp/possible solution for it, after researching for more than 2 weeks.
Use
onPressIninstead ofonPress!Let me know if it also works for you. Also to increase tappable area to make button more responsive, you can use
hitslopprop.vrgimael commentedon Jun 28, 2023
This is not a solution as it triggers accidentally on any scrollable item
jugshaurya commentedon Jun 28, 2023
Can you share an example gif or something to get the better context, because i used this solution for codebase, it is working fine.
github-actions commentedon Dec 26, 2023
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
github-actions commentedon Jan 2, 2024
This issue was closed because it has been stalled for 7 days with no activity.
14 remaining items
fdecampredon commentedon Oct 29, 2024
@61xin After upgrading to 0.76.1 I can say that the issue is still present
cipolleschi commentedon Oct 31, 2024
@fdecampredon can you share a reproducer? We have a screen in RNTester to test this case and I'm sure it was fixed. Maybe we missed some edge case.
fdecampredon commentedon Nov 22, 2024
@cipolleschi I'm really sorry after more investigation I think it is more related to this one : #44768.
We'll try to make a minimal reproduction example but it's a bit hard since the problem is deeply nested in a very complex screen.
ZhangBinglei2015 commentedon Dec 12, 2024
I am using react native 0.72 and this solve my problem,you can try it!
kirillzyusko commentedon May 21, 2025
@cipolleschi I believe I encountered a very similar issue and thought to ask your help 😅
Basically I have this component:
Where
useKeyboardAnimationsimply subscribes to the context (that stores animated value):And here I have few strange observations:
progress/heightvalues throughonKeyboardMove- the issue becomes reproducible.ScrollView(that also updatesheight/progress), thenonPresshandler works well again;KeyboardStickyViewthen the issue will gone too.It seems like I encounter exactly the problem described in #45413 But what I don't understand is why events sent through
ScrollViewworks as expected, but events sent fromKeyboardControllerViewsomehow updates an animated value, but don't "commit" final position, so that touches gets rejected?I would appreciate any help/response from you 🙌
kirillzyusko commentedon May 21, 2025
Okay, after a little bit debugging I found out, that one scroll gets performed all Animated.View gets re-rendered:
Including my view
And it actually explains a lot. If I understand correctly that re-render synchronizes C++ state with native-driver animations state, so that all Touchables are aware about layout shift and can correctly fire
onPress🤔The open question now is how
onScrollEndevent notifies all animated views to re-render them 👀kirillzyusko commentedon May 21, 2025
After digging in the code even more I realized that for a
ScrollViewyou additionally calluserDrivenScrollEndedmethod, which sendsonUserDrivenAnimationEndedevent, and this event gets broadcasted to allAnimated.Views:While I understand, that this approach works for
ScrollView... Is this approach scalable? For example I may want to sendonUserDrivenAnimationEndedwhen keyboard finishes its animation to synchronize shadow-tree, but keyboard animation is not even user-driven animation 🙈And theoretically for each 3rd party package that drives animations (i. e. changes
translatevia native driver) we have to add this "synchronization" code?fix: keep shadow nodes in sync (#950)
cipolleschi commentedon Jun 9, 2025
@kirillzyusko sorry for the delay... You performed a very deep investigation, so you have discovered almost everything yourself! :D
The problem here is how to keep the react tree in sync with the shadow tree and that in sync with the native tree.
The approach of
onUserDrivenAnimationEndedworks withScrollViewand every component based onScrollViewgets it for free.This works for animation driven by the user, because we don't know when the animation actually ends.
For timed animations, such as the opening/closing of the keyboard, we know exactly when the Animation end. We also usually have a callback for it. In those cases, there is another events that the component should emit, that forces the alignment of the trees: i think that is
onAnimatedValueUpdate, but I might have to double check.It should be the same event emitted by scroll view when you call
scrollTo.When we have natively driven animations, sending an event from native to JS is the only way to tell React that the trees need to be realigned.
It scales, as an approach, but we would have to be clearer with our Documentation, and given that the code changes so fast, we haven't been as good as we should with that.
We are also exploring other alternatives to the Animated backend, so I hope that the situation could improve soon!
Make layout queries aware of synchronously updated transforms
Make layout queries aware of synchronously updated transforms
Make layout queries aware of synchronously updated transforms
Make layout queries aware of synchronously updated transforms
Make layout queries aware of synchronously updated transforms
Make layout queries aware of synchronously updated transforms