Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native onStartShouldSetResponder and onResponderRelease?

I've created a button that I want to have call a function on click and then again on release. A normal TouchableOpacity or other will trigger a function upon release of a click only, I need functions on both click AND release.

<View
    style={styles.touchbutton}
    onStartShouldSetResponder={() => this.clickOn()}
    onResponderRelease={() => this.clickRelease()}>
    <Text style={styles.dark}>Button</Text>
</View>

The above code works on click but not on release. I also tried onResponderReject but that doesn't work either. Hard to find what the command should be.

like image 900
Hasen Avatar asked Apr 21 '16 02:04

Hasen


People also ask

How do I turn off touchable opacity in React Native?

We will introduce how to disable the button in react. js using a disabled prop to our button element. To simply disable the button, we can use the disabled prop in our button element and set its value to true . If we want to disable our button after clicking on it, We can disable it by using react's state.

How do you check if view is visible on screen React Native?

You can use onViewableItemsChanged to check which viewableItems are on the screen.

How do I use pointerEvents in React Native?

js */ import React from "react"; import { Button, StyleSheet, Text, View } from "react-native"; function App() { const getDeviceType = (e) => { console. log(e); }; return ( <View style={styles. app} pointerEvents="box-none"> <View style={styles. header}> <Text style={styles.

Can we use HTML tags in React Native?

Unfortunately, React Native's basic components currently can't render to basic HTML elements. Your React Native code can be reused across iOS and Android (and any future React Native platforms), but it can't render to web-compatible views.


1 Answers

Had the same problem. onStartShouldSetResponder needs to return true.

onStartShouldSetResponder={(e) => {
    /*do whatever*/;
    return true
}}
like image 155
pwcremin Avatar answered Sep 18 '22 23:09

pwcremin