3
A
回答
0
感谢@Vincent我设法让类似的,简单的代码来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>
);
}
}
1
隐藏NavigatorIOS酒吧是不可能的,而滚动。基于这个issue,导航器在一个静态组件内,这意味着该条在状态改变时不会被重新展示。所以如果条已经被渲染,你就不能隐藏它。您只能在呈现新路线之前隐藏它。如果你真的想隐藏滚动时的导航栏,您可以尝试使用这个库,而不是:react-native-navbar
如何使用做反应,本机导航栏:
- 隐藏与NavigatorIOS酒吧为您的组件scrollView
- 在此组件中,在scrollView上,使用自定义函数处理滚动,该自定义函数将更新组件状态,这将重新渲染组件。
- 根据你的状态,隐藏或显示导航栏。
- 在您的自定义导航栏控件上,绑定您通常使用的NavigatorIOS弹出窗口,推送,替换等操作。
您可以按照this issue帮助您该怎么办呢
你的组件将是这样的:
class CustomComponent extends Component {
state = { isNavBarHidden: false };
handleScroll =() => this.setState({ isNavBarHidden: true });
render() {
const navbarStyle = this.state.isNavBarHidden ? { height: 0 } : {};
return (
<View>
<NavigationBar style={navbarStyle} />
<ScrollView onScroll={this.handleScroll}>
...
</ScrollView>
</View>
);
}
}
编辑:这是用动画的高度完整的导航栏的例子。您可以使用Animated.createAnimatedComponent
函数为所有想要的动画制作动画。如果你想正确地设置按钮的标题动画,你将不得不使用它。我使用64作为高度,因为它是iOS导航栏高度,但在android上,高度不同,如果需要使其适用于android,则可以使用Platform.select()
。您还可以指定高度5而不是0,以始终使导航栏的一部分可见并可按下。在这个例子中,导航栏会隐藏或显示在每个滚动条上,您可能必须隐藏它并根据您想要实现的内容显示它。
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 = enable => {
Animated.timing(this.state.height, {
duration: 400,
toValue: enable? 64 : 0
}).start()
};
handleScroll =() => {
this.setAnimation(this.state.isNavBarHidden);
this.setState({ isNavBarHidden: !this.state.isNavBarHidden });
};
render() {
return (
<View style={{ flex: 1 }} >
<AnimatedNavigationBar style={{ backgroundColor: 'red', height: this.state.height }} />
<ScrollView onScroll={this.handleScroll}>
<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>
);
}
}
相关问题
- 1. 滚动时隐藏bootstrap导航栏
- 2. 隐藏导航向下滚动并仅在移动时向上滚动
- 3. 导航抽屉打开时如何隐藏滚动条
- 4. 页面菜单,滚动时隐藏导航栏
- 5. 滚动时隐藏和显示导航栏
- 6. 如何向下滚动时隐藏导航栏?
- 7. 如何在滚动时隐藏导航栏
- 8. 当不在ListView中滚动时自动隐藏滚动条
- 9. 隐藏滚动导航栏 - 运动员的WordPress主题
- 10. 滚动时隐藏溢出
- 11. UIProgressView滚动uitableview时隐藏
- 12. 浏览器窗口底部的自动隐藏导航
- 13. 溢出隐藏自动滚动
- 14. 的jCarousel自动滚动导航设置
- 15. 垂直菜单/导航自动滚动
- 16. 带导航的jQuery Browser自动滚动?
- 17. 堆栈上滚动的隐藏导航栏的div ontop
- 18. 隐藏和显示基于滚动位置的导航箭头
- 19. 粘滞导航隐藏,直到滚动页面
- 20. 隐藏/显示滚动浏览导航Contoller
- 21. Scrollify滚动之前,隐藏导航标题/揭示用jQuery
- 22. 隐藏导航栏不移动scrollView
- 23. 隐藏滚动条
- 24. 隐藏滚动条
- 25. 隐藏滚动条
- 26. 使用Webview滚动时隐藏浮动按钮隐藏
- 27. HighCharts导出隐藏滚动条
- 28. 更改ScrollViewer滚动条自动隐藏定时器的默认时间
- 29. 如何自动隐藏Windows浏览器上的滚动条
- 30. 隐藏滚动条如果不滚动
不可能的? AMScrollingNavbar如何做 – bader
他们创建了自己的导航栏。 AMScrollingNavbar不是反应原生库,它是一个原生的iOS库。你可以使用它,如果你想创建相应的反应类。或者,您也可以修改react-native代码以从其静态组件封装器中删除NavigatorIOS,但我不会推荐它。目前,NavigatorIOS以react-native编码的方式不允许您在路由组件中重新渲染它,这就是为什么我建议您使用另一个库。 –
它可以被移植,但它的写入速度很快,所以它不是一件容易的事情。react-native-bar声音不错,但是我正在寻找一些看起来很原生的东西......非常感谢,如果你用动画解释你的示例代码。 ...谢谢 – bader