react-native-navigation的迁移库

ScrollViewScreen.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const { StyleSheet, ScrollView, View, Button, Platform } = require('react-native');
  4. const { Navigation } = require('react-native-navigation');
  5. const testIDs = require('../testIDs');
  6. const FAB = 'fab';
  7. class ScrollViewScreen extends Component {
  8. static options() {
  9. return {
  10. topBar: {
  11. title: {
  12. text: 'Collapse',
  13. color: 'black',
  14. fontSize: 16
  15. },
  16. drawBehind: true,
  17. visible: true,
  18. testID: testIDs.TOP_BAR_ELEMENT
  19. },
  20. fab: {
  21. id: FAB,
  22. backgroundColor: 'blue',
  23. clickColor: 'blue',
  24. rippleColor: 'aquamarine',
  25. hideOnScroll: true
  26. }
  27. };
  28. }
  29. constructor(props) {
  30. super(props);
  31. this.state = {
  32. topBarHideOnScroll: false
  33. };
  34. this.onClickToggleTopBarHideOnScroll = this.onClickToggleTopBarHideOnScroll.bind(this);
  35. this.onClickPop = this.onClickPop.bind(this);
  36. }
  37. render() {
  38. return (
  39. <View>
  40. <ScrollView testID={testIDs.SCROLLVIEW_ELEMENT} contentContainerStyle={styles.contentContainer}>
  41. <View>
  42. <Button title='Toggle Top Bar Hide On Scroll' testID={testIDs.TOGGLE_TOP_BAR_HIDE_ON_SCROLL} onPress={this.onClickToggleTopBarHideOnScroll} />
  43. <Button title='Pop screen' testID={testIDs.POP_BUTTON} onPress={this.onClickPop} />
  44. </View>
  45. </ScrollView>
  46. </View>
  47. );
  48. }
  49. onClickToggleTopBarHideOnScroll() {
  50. this.setState({
  51. topBarHideOnScroll: !this.state.topBarHideOnScroll
  52. });
  53. }
  54. onClickPop() {
  55. Navigation.pop(this.props.componentId);
  56. }
  57. componentDidUpdate() {
  58. Navigation.mergeOptions(this.props.componentId, {
  59. topBar: {
  60. hideOnScroll: this.state.topBarHideOnScroll
  61. },
  62. fab: {
  63. hideOnScroll: !this.state.topBarHideOnScroll
  64. }
  65. });
  66. }
  67. }
  68. module.exports = ScrollViewScreen;
  69. const styles = StyleSheet.create({
  70. contentContainer: {
  71. alignItems: 'center',
  72. backgroundColor: 'green',
  73. paddingTop: 200,
  74. height: 1200
  75. }
  76. });