Skip to content

Instantly share code, notes, and snippets.

@zdying
Created March 29, 2017 15:02
Show Gist options
  • Save zdying/60596db1f72cfbedfdca66bddc04a530 to your computer and use it in GitHub Desktop.
Save zdying/60596db1f72cfbedfdca66bddc04a530 to your computer and use it in GitHub Desktop.
ActionSheetAndroid
/**
* @file ActionSheet API
* @author zdying
* @providesModule ActionSheet
*/
import React, {Component} from 'react';
import {Modal, Text, View, TouchableWithoutFeedback} from 'react-native';
export default class ActionSheet extends Component {
constructor(props, state){
super(props, state);
global.__action_sheet = this;
this.state = {
visible: false
}
}
show(message){
this.setState({
visible: true,
message
})
}
hide(){
this.setState({
visible: false
})
}
render(){
return (
<Modal visible={this.state.visible} transparent={true}>
<TouchableWithoutFeedback onPress={this.hide.bind(this)} style={{
flex: 1,
backgroundColor: 'red',
marginTop: 20
}}>
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: 'rgba(0, 0, 0, 0.4)'}}>
<Text style={{color: 'white'}}>
{this.state.message}
</Text>
</View>
</TouchableWithoutFeedback>
</Modal>
)
}
}
ActionSheet.show = (msg) => {
global.__action_sheet.show(msg);
}
ActionSheet.hide = (msg) => {
global.__action_sheet.hide();
}
global.ActionSheet = ActionSheet;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment