react-native-navigation的迁移库

ScrollViewScreen.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 get 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. }
  36. render() {
  37. return (
  38. <View>
  39. <ScrollView testID={testIDs.SCROLLVIEW_ELEMENT} contentContainerStyle={styles.contentContainer}>
  40. <View>
  41. <Button title='Toggle Top Bar Hide On Scroll' testID={testIDs.TOGGLE_TOP_BAR_HIDE_ON_SCROLL} onPress={this.onClickToggleTopBarHideOnScroll} />
  42. </View>
  43. </ScrollView>
  44. </View>
  45. );
  46. }
  47. onClickToggleTopBarHideOnScroll() {
  48. this.setState({
  49. topBarHideOnScroll: !this.state.topBarHideOnScroll
  50. });
  51. }
  52. componentDidUpdate() {
  53. Navigation.setOptions(this.props.componentId, {
  54. topBar: {
  55. hideOnScroll: this.state.topBarHideOnScroll
  56. },
  57. fab: {
  58. hideOnScroll: !this.state.topBarHideOnScroll
  59. }
  60. });
  61. }
  62. }
  63. module.exports = ScrollViewScreen;
  64. const styles = StyleSheet.create({
  65. contentContainer: {
  66. alignItems: 'center',
  67. backgroundColor: 'green',
  68. paddingTop: 200,
  69. height: 1200
  70. }
  71. });