onpress

Return JSX component onPress react-native

一笑奈何 提交于 2021-01-28 08:38:21
问题 I want to prompt users to get input onPress but returning JSX from an onPress never worked so whats a possible workaround to return JSX based on button click. Here's my code: import React, { useState } from 'react'; import { StyleSheet, KeyboardAvoidingView, View, Text, TouchableOpacity } from 'react-native'; import InputPrompt from './InputPrompt' const Newact = (props) => { const [visible, setVisible] = useState(false) return( <View> <View style={styles.button} > <TouchableOpacity style=

React Native— onPress extract id from “currentTarget”

偶尔善良 提交于 2019-12-23 01:34:31
问题 I have created a game on React and I am trying to adapt my code to React Native. One of the things that is troubling me is how to translate these three lines, since in RN there are no DOM solutions to rely on: handleClick(e) { this.props.change(e.currentTarget.id); } What is happening here is that a stateless child is harvesting a clicked elements id (the currentTarget's) and is using it to call with it a method defined inside the parent. This kind of formulation e.currentTarget.id however

React Native change view onPress

杀马特。学长 韩版系。学妹 提交于 2019-12-13 02:42:56
问题 I have searched on google but I don't know react. When I click on the button 'Connexion' I would like to be forwarded to the page About.js. My app.js : import React from 'react'; import {View, TextInput, StyleSheet, Text } from 'react-native'; import { Header, Button } from 'react-native-elements'; import About from './component/About'; export default class App extends React.Component { render() { return ( <View style={{flex: 1}}> <Button title="CONNEXION" buttonStyle={{backgroundColor: "

React Native— onPress extract id from “currentTarget”

社会主义新天地 提交于 2019-12-07 02:39:27
I have created a game on React and I am trying to adapt my code to React Native. One of the things that is troubling me is how to translate these three lines, since in RN there are no DOM solutions to rely on: handleClick(e) { this.props.change(e.currentTarget.id); } What is happening here is that a stateless child is harvesting a clicked elements id (the currentTarget's) and is using it to call with it a method defined inside the parent. This kind of formulation e.currentTarget.id however does not work in RN. Is there an eloquent way to re-write this one liner in RN? Note: there are two

Get name of button onPress in react native

拥有回忆 提交于 2019-12-01 04:11:05
问题 I have two buttons that both call the same onPress function. In the callback I want to be able to differentiate between which was pressed. <MKRadioButton title='A' group={this.radioGroup} onPress={this._toggle} /> <MKRadioButton title='B' group={this.radioGroup} onPress={this._toggle} /> then the call _toggle(event) { //what should go here to figure out if title A or B was called? } 回答1: One solution is to pass that info as a parameter: <MKRadioButton title='A' group={this.radioGroup} onPress