0
我使用的是來自Native Base
的真棒<Picker>
組件。React Native:onPress觸發另一個onPress
import React, { Component } from 'react'
import {View, Picker, Text, Button, Icon} from 'native-base'
export default class PickSomething extends Component {
constructor(props) {
super(props)
this.state = {
SelectedValue: 'Foo',
}
}
render() {
return (
<View >
<Text>Type: </Text>
<Picker
iosHeader="Select a Type"
selectedValue={this.state.SelectedValue}
onValueChange={(value) => {
this.setState(
(prevState, props) => ({SelectedValue: value})
)}}>
<Picker.Item label="Foo" value="Foo" />
<Picker.Item label="Bar" value="Bar" />
</Picker>
<Button
onPress={() =>
//trigger the <Picker>onPress
}>
<Icon name="ios-arrow-dropdown-circle-outline"/>
</Button>
</View>
)}
}
我希望它更明顯,這是一個下拉菜單。我如何使Button onPrees
觸發Picker
的onPress?
但您沒有在Picker上定義onPress?你能用onPress代碼更新你的問題嗎? –
默認情況下,onPress行爲是基於本地組件構建的 – Norfeldt
下面是一個解決方案:https://github.com/facebook/react-native/issues/7817#issuecomment-264837382 –