我试图在向下滚动时隐藏导航栏(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/