react-native 滑动ScrollView 隐藏导航

本文介绍如何在React-Native应用中,通过滑动ScrollView实现导航栏的隐藏。示例代码展示了如何设置静态导航选项并使用 Animated 库进行动画效果。
摘要由CSDN通过智能技术生成

react-native 滑动ScrollView 隐藏导航

import React from ‘react’
import {View, Text, ScrollView, Button, StyleSheet,Animated} from ‘react-native’
import { observer, inject } from ‘mobx-react’

@inject([‘homeStore’])
@observer
class HomePage extends React.Component{
static navigationOptions = {
title: ‘Home’,
header: null,
};

constructor() {
	super();
	this.state = {
		headerTop: new Animated.Value(0)
	}
}

componentWillMount() {
	// P.S. 270,217,280区间的映射是告诉interpolate,所有大于270的值都映射成-50
	// 这样就不会导致Header在上滑的过程中一直向上滑动了
	this.top = this.state.headerTop.interpolate({
		inputRange: [0, 270, 271, 280],
		outputRange: [0, -65, -65, -65]
	});

	this.animatedEvent = Animated.event([
		{
			nativeEvent: {
				contentOffset: { y: this.state.headerTop }
			}
		}
	])
}

_onPress = () => {
	this.props.navigation.navigate('Detail')
};

onScroll &#
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值