-
Notifications
You must be signed in to change notification settings - Fork 515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Touchables in Interactable.View #187
Comments
Ok, I searched a long time for a workaround on this issue. I've came to the idea of having all my Then I added an It looks like the Here's my code (simplified for understanding) : <Interactable.View
animatedNativeDriver={true}
dragEnabled={this.state.editMode}
>
<TouchableOpacity
onPress={() => alert('Touchable Pressed')}
onLongPress={() => this.setState({editMode: true})}
>
<Text>Test Button</Text>
</TouchableOpacity>
</Interactable.View> |
Any one found a solution for this issue? |
I think this issue is not resolvable in any way... It's not wix's issue here but rather how touchables behave in react-native Android. Maybe we should try to develop a module that wraps the native Android Button component. I'll try to explore more on that next week since this issue stills blocks me. |
Ok, I managed to solve my issue by using the React Native Animated library and PanResponder. This is how I did it: First I created an Animated.ValueXY for my bubble position. It is animated by my PanResponder on Drag. In my onResponderRelease I check if the user dragged more that 3 pixels. If not, I launch the onPress manually by calling .touchableHandlePress() on my TouchableOpacity instance. By doing it this way, I don't have to worry anymore if my touchable is catching the drag. My PanResponder captures everything. And I chose when the button is actually pressed. I also mimic the button feel by manually setting the opacity on the instance. const position = new Animated.ValueXY({x: 0, y: 0});
const panResponder = PanResponder.create({
onStartShouldSetPanResponder: () => true,
onStartShouldSetPanResponderCapture: (evt, gestureState) => {
// Set opacity of button to half
this._touchable.setOpacityTo(0.5, 100);
// PanResponder always capturing
return true;
},
// At each drag start
onPanResponderGrant: (evt, gestureState) => {
// Add offset of last position
position.setOffset(position.__getValue());
// Resets to x:0 and y:0
position.setValue({ x: 0, y: 0 });
},
onPanResponderMove: (event, gesture) => {
// If user drags more that 3px around
if (gesture.dx > 3 || gesture.dy > 3 || gesture.dy < -3 || gesture.dx < -3) {
// Start moving the view around
position.setValue({ x: gesture.dx, y: gesture.dy });
// Reset button Opacity
this._touchable.setOpacityTo(1, 100);
}
},
// When the user releases touch
onPanResponderRelease: (event, gesture) => {
// If the user didn't move more than 3px around, I consider it as a press on the button
if (gesture.dx < 3 && gesture.dx > -3 && gesture.dy < 3 && gesture.dy > -3) {
// Launch button on click
this._touchable.touchableHandlePress();
// Reset button opacity
this._touchable.setOpacityTo(1, 100);
}
}
}); My component : <Animated.View
style={...this.state.position.getLayout()}
{...this.state.panResponder.panHandlers}
>
<TouchableOpacity
onPress={() => alert("Click")}
ref={(touchable) => this._touchable = touchable}
style={styles.littleCircle}
/>
</Animated.View> I also recreated the SnapPoints system but no need to show it here. HMU if anybody wants a gist |
Thanks a lot bro ... I was starting to implement this using animated .. can u share the gist? |
@DEEvent Can u share the code? |
@victorileaf @victorkvarghese Sure ! Here's the link to the gist and how I managed to do it : https://gist.github.com/Deevent/6300fb3531e6e526a880a82b98c049a6 |
Thank you, @DEEvent! But how can we drag the interactable, if the view inside it captures all events? |
@DEEvent How to use the Bubble? Could you provide a demo? |
Please use react-native-interactable-button instead. It solves the conflict between dragging events and clicking events. |
Does anyone know what this is caused by? I'm trying to fix the java code. |
I searched everywhere ..almost everyone said the same .. It's not wix's issue here but rather how touchables behave in react-native Android. Couldn't go deep into why this happens though... |
Are there any resources you can point me towards? |
I tried another lib.. react native gesture handler.. there is a chat heads functionality .. it works flawlessly on iOS but issues with Android. https://github.com/kmagiera/react-native-gesture-handler/tree/master/Example/chatHeads |
Solid link, I didn't know about that repo. I managed to fix this issue in my fork. Tested on a physical device. Additional issues are welcome over there. |
@woodpav .. what's was the issue .. ? Can you explain how you fixed it if possible.. |
is this merged in master ? |
@woodpav can you publish your own fork on npm? |
Android only. This is still an issue. The PR adding |
@woodpav What exactly does your fork solve? I'm looking to avoid the bugs being described in these issues... |
It fixes Touchables on Android and a few other things if I remember right. With my fork I am not experiencing the issues @parohy mentioned. That said I recently moved away from this package in favor of PanResponder. This package needs to be updated to AndroidX for react-native 0.60+ and PanResponder tends to be more stable given that it is officially maintained. I also noticed that PanResponder onMove is slightly faster than adding a listener to the Interactive.View animatedValue. If you really want to use this package, I suggest my fork. If you're unsure, try to get PanResponder working. Furthermore, due to Interactive.View API decisions I noticed that PanResponder implementions use ~50% less code for my use case. |
Ok, I'm basically looking to implement the google maps bottom sheet type thing. And wix had that as one of their examples. But the As for the PanResponder, do you think it would be too difficult to do this myself with it? |
I have tried a lot of implementations to do a very similar thing. I finally settled on a PanRepsonder in a ScrollView. Using this package works but the bugs are numerous especially because of the way Android captures touches and this package intercepts them. You'll run into problems with ScrollView like others are running into issues with Touchables. Feel free to send me some code and we can discuss further. My email is [email protected]. |
@JakeHadley Alternatively you can send me stuff on GitHub so others can gain from our learnings. You can open an issue in my repo and we can reference it here so others in this thread don't get extra notifications. |
I'll do that. I'll use your repo and see what happens and open an issue. |
@woodpav Issue created. |
hey @parohy I am also facing a similar issue on Android. did you manage to fix it? |
Hello,
I'm currently facing an issue only on Android. When I press a touchable inside an Interactable.View it's never fired. It looks like the views are way more sensitive in Android and I have to press very straight and without moving my finger.
On ios, it's working perfectly
Has somebody else faced a similar issue ?
The text was updated successfully, but these errors were encountered: