react-native-navigation的迁移库

CustomTopBar.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const {
  4. StyleSheet,
  5. View,
  6. TouchableOpacity,
  7. Text,
  8. Alert,
  9. Platform
  10. } = require('react-native');
  11. const { Navigation } = require('react-native-navigation');
  12. class CustomTopBar extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {};
  16. this.subscription = Navigation.events().bindComponent(this);
  17. }
  18. componentDidAppear() {
  19. console.log('RNN', 'CTB.componentDidAppear');
  20. }
  21. componentDidDisappear() {
  22. console.log('RNN', `CTB.componentDidDisappear`);
  23. }
  24. componentDidMount() {
  25. console.log('RNN', `CTB.componentDidMount`);
  26. }
  27. componentWillUnmount() {
  28. console.log('RNN', `CTB.componentWillUnmount`);
  29. this.subscription.remove();
  30. }
  31. render() {
  32. return (
  33. <View style={styles.container}>
  34. <TouchableOpacity onPress={() => Alert.alert(this.props.title, 'Thanks for that :)')}>
  35. <Text style={styles.text}>Press Me</Text>
  36. </TouchableOpacity>
  37. </View>
  38. );
  39. }
  40. }
  41. module.exports = CustomTopBar;
  42. const styles = StyleSheet.create({
  43. container: {
  44. flex: 1,
  45. flexDirection: 'column',
  46. justifyContent: 'center',
  47. alignSelf: 'center'
  48. },
  49. text: {
  50. alignSelf: 'center',
  51. color: 'black',
  52. }
  53. });