import React, { Component } from 'react';
import { View } from 'react-native';
import { ActionSheet, Button, Text } from 'native-base';
class Foo extends Component {
constructor(props) {
super(props);
this.actionSheet = null;
}
render() {
return (
<View>
<Button onPress={() => this.showActionSheet()}>
<Text>Action Sheet!</Text>
</Button>
<ActionSheet ref={(c) => { this.actionSheet = c; }} />
</View>
);
}
showActionSheet() {
if ( this.actionSheet !== null ) {
// Call as you would ActionSheet.show(config, callback)
this.actionSheet._root.showActionSheet({options: [1,2,3]}, (i) =>
console.log(i));
}
}
}
顯示
this.actionSheet._root.showActionSheet({ options: BUTTONS }, (i) => console.log(i) )
隱藏
this.actionSheet._root.hideActionSheet()
使用 native-base ActionSheet
經常會 報錯
cannot read property _root of null
cannot read property 'showactionsheet' of null