Last active
January 26, 2018 16:33
-
-
Save FiberJW/8149b84df7479925e857ea40d4739f68 to your computer and use it in GitHub Desktop.
react-native-dropdown-alert hacks
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
import React, { PropTypes } from "react"; | |
import hoistNonReactStatic from "hoist-non-react-statics"; | |
export default function connectDropdownAlert(WrappedComponent) { | |
const ConnectedDropdownAlert = (props, context) => { | |
return ( | |
<WrappedComponent | |
{...props} | |
alertWithType={context.alertWithType} | |
alert={context.alert} | |
/> | |
); | |
}; | |
ConnectedDropdownAlert.contextTypes = { | |
alertWithType: PropTypes.func, | |
alert: PropTypes.func | |
}; | |
return hoistNonReactStatic(ConnectedDropdownAlert, WrappedComponent); | |
} |
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
import React, { PropTypes, Component } from "react"; | |
import { View, StyleSheet, StatusBar } from "react-native"; | |
import DropdownAlert from "react-native-dropdownalert"; | |
import { observer } from "mobx-react/native"; | |
import { observable } from "mobx"; | |
@observer | |
export default class DropdownAlertProvider extends Component { | |
static propTypes = { | |
children: React.PropTypes.any | |
}; | |
static childContextTypes = { | |
alertWithType: PropTypes.func, | |
alert: PropTypes.func | |
}; | |
@observable barStyle = "default"; | |
getChildContext() { | |
return { | |
alert: (...args) => this.dropdown.alert(...args), | |
alertWithType: (...args) => this.dropdown.alertWithType(...args) | |
}; | |
} | |
render() { | |
return ( | |
<View style={styles.container}> | |
<StatusBar barStyle={this.barStyle} /> | |
{React.Children.only(this.props.children)} | |
<DropdownAlert | |
ref={ref => { | |
this.dropdown = ref; | |
}} | |
onClose={() => { | |
this.barStyle = "default"; | |
}} | |
endDelta={StatusBar.currentHeight} | |
/> | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you explain the usage mate ? how to use this feature on ui screen ?