Created
March 29, 2017 15:02
-
-
Save zdying/60596db1f72cfbedfdca66bddc04a530 to your computer and use it in GitHub Desktop.
ActionSheetAndroid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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