Skip to content
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

Handle Button OnPress in renderContent ! #219

Open
dungkaka opened this issue May 2, 2020 · 9 comments
Open

Handle Button OnPress in renderContent ! #219

dungkaka opened this issue May 2, 2020 · 9 comments

Comments

@dungkaka
Copy link

dungkaka commented May 2, 2020

I create header and content in bottom-sheet.
In renderHeader, i can create a button and handle onPress() perfectly.
Unfortulately, it's not in renderContent. I need to press long to excute onPress().
When I add enabledContentGestureInteraction={false}, now I can press on button normally, but I can not interact with modal up and down any more.
I test on my real device: samsung s7 !
How can I create a button with normal onPress event in renderContent ?

@dungkaka
Copy link
Author

dungkaka commented May 2, 2020

I found solution from previous issue. For Android, I use TouchableOpacity from ""react-native-gesture-handler" and fixed problems. I will close this issue soon, or anyone have any other ideas to fix this ?

@ryantando
Copy link

ryantando commented May 5, 2020

@dungkaka solution seems to work. Tested on real device also (samsung s10)

@MinhazMM
Copy link

MinhazMM commented May 6, 2020

I found solution from previous issue. For Android, I use TouchableOpacity from ""react-native-gesture-handler" and fixed problems. I will close this issue soon, or anyone have any other ideas to fix this ?

Does this only work for Android? Because I tried for iOS via the following code and it didn't work

import {
  TouchableOpacity,
} from 'react-native-gesture-handler';
renderInner = () => (
    <View style={styles.panel}>
      <Text style={styles.panelTitle}>San Francisco Airport</Text>
      <Text style={styles.panelSubtitle}>
        International Airport - 40 miles away
      </Text>
      <TouchableOpacity style={styles.panelButton} onPress={alert('GG')}>
        <Text style={styles.panelButtonTitle}>Directions</Text>
      </TouchableOpacity>
      <View style={styles.panelButton}>
        <Text style={styles.panelButtonTitle}>Search Nearby</Text>
      </View>
      <Image
        style={styles.photo}
        source={require('./assets/airport-photo.jpg')}
      />
    </View>
  );

Am I doing anything wrong or is it actually not working for iOS?

@dungkaka
Copy link
Author

dungkaka commented May 6, 2020

@MinhazMM , from this post, someone said that they just used TouchableOpacity from "react-native" on IOS and worked fine. On IOS, you don't need to change TouchableOpacity from "react-native-gesture-handler". I'm not sure because I have not try it on iOS. You can follow this post if anything information may be helpful !
Link: #16

@ValentinH
Copy link

@dungkaka I had the same issue and solve it simply by setting enabledContentTapInteraction={false}.

@baijii
Copy link

baijii commented May 9, 2020

Yeah, it's kind of annoying. On iOS only the ones from react-native seems to work, and on Android only the ones from react-native-gesture-handler, so I made myself a little helper module:

// touchables.js

import {
  Platform,
  TouchableHighlight as TouchableHighlightIOS,
  TouchableOpacity as TouchableOpacityIOS,
  ScrollView as ScrollViewIOS,
} from 'react-native'

import {
  TouchableHighlight as TouchableHighlightAndroid,
  TouchableOpacity as TouchableOpacityAndroid,
  ScrollView as ScrollViewAndroid,
} from 'react-native-gesture-handler'

export const TouchableHighlight = (Platform.OS === 'android')
  ? TouchableHighlightAndroid
  : TouchableHighlightIOS

export const TouchableOpacity = (Platform.OS === 'android')
  ? TouchableOpacityAndroid
  : TouchableOpacityIOS

export const ScrollView = (Platform.OS === 'android')
  ? ScrollViewAndroid
  : ScrollViewIOS

// component.js

import { TouchableOpacity } from './touchables'
...

@jtomaszewski
Copy link
Contributor

I use TouchableWithoutFeedback from react-native together with enabledContentTapInteraction={false} and it works well on both Android and iOS.

jtomaszewski added a commit to jtomaszewski/react-native-reanimated-bottom-sheet that referenced this issue Jun 4, 2020
@wmonecke
Copy link

wmonecke commented Aug 2, 2020

This is the current workaround:

import { Platform } from 'react-native';
const TouchableOpacity = 
    Platform.OS === 'ios' ? require('react-native').TouchableOpacity : require('react-native-gesture-handler').TouchableOpacity;

@jspizziri
Copy link

@jtomaszewski

Based on what I'm seeing enabledContentTapInteraction needs to be set differently based on the platform (not sure why this is happening). But here's what I'm doing which finally get's it to work:

  1. I'm using only Touchables from react-native-gesture-handler inside renderContent elements.
  2. On Android I'm setting enabledContentTapInteraction={true}.
  3. On iOS I'm setting enabledContentTapInteraction={false}.

Hopefully, this helps someone. Or perhaps someone will explain to me either what I'm doing wrong, or why it works this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants