javascript - 滚动时 react native 自动隐藏导航 ios

标签 javascript reactjs react-native navigator-ios

我试图在向下滚动时隐藏导航栏(NavigatorIOS)。我怎样才能做到这一点?

谢谢

最佳答案

感谢@Vincent我设法在 React Native 中制作了与 AMScrollingnavbar 类似的简单代码。(P.S:它有一个小故障,但我对整体结果感到满意)

import React, { Component } from 'react';
import { Text, View, ScrollView, Animated } from 'react-native';
import NavigationBar from 'react-native-navbar';

const AnimatedNavigationBar = Animated.createAnimatedComponent(NavigationBar);

export default class BasicListView extends Component {

  state = { isNavBarHidden: false, height: new Animated.Value(64) };

  setAnimation(disable) {
    Animated.timing(this.state.height, {
      duration: 100,
      toValue: disable ? 0 : 64
    }).start()
  };

   handleScroll(event) {
      this.setAnimation((event.nativeEvent.contentOffset.y > 64));
      this.setState({ isNavBarHidden: !this.state.isNavBarHidden });
  }

  render() {
    return (
      <View style={{ flex: 1 }} >
        <AnimatedNavigationBar style={{ backgroundColor: 'red', height: this.state.height }} />
        <ScrollView scrollEventThrottle={16} onScroll={this.handleScroll.bind(this)}>
          <View style={{ height: 200 }}><Text>Test</Text></View>
          <View style={{ height: 200 }}><Text>Test</Text></View>
          <View style={{ height: 200 }}><Text>Test</Text></View>
          <View style={{ height: 200 }}><Text>Test</Text></View>
          <View style={{ height: 200 }}><Text>Test</Text></View>
        </ScrollView>
      </View>
    );
  }
}

关于javascript - 滚动时 react native 自动隐藏导航 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42632810/

相关文章:

javascript - 使用 Node.js 获取大文件进行处理

javascript - 使用 `fetch()`在网页中显示纯文本

ajax - axios跨域

javascript - 在平面列表中 react native 导航

javascript - Highcharts setState() 上的 3D 渲染问题

reactjs - 简单样式组件和 Typescript 设置类型检查错误

android - react native : Generating the Release Build APK error :app:mergeReleaseAssets FAILED

reactjs - 如何在 React Native 中播放 Lottie 动画(.json 文件)的片段

react-native - 如何使用expo React Native相机拍照?

javascript - 从 json 数据更新图表