基於React Native官方元件ScrollView與React-Navigation實現headerTitle與介面的滑動的互動效果react-native-scrollable-contain
阿新 • • 發佈:2018-11-12
react-native-scrollable-container
基於React Native官方元件ScrollView與React-Navigation實現headerTitle與介面的滑動的互動效果
Installation
npm install react-native-scrollable-container --save
Import into your project
import ScrollContainer from 'react-native-scrollable-container';
Examle useage
static navigationOptions = ({ navigation }) => ({
...ThemeStyles.indexHeaderStyle,
headerTitleStyle: {
...ThemeStyles.indexHeaderStyle.headerTitleStyle,
opacity: navigation.getParam('opacity', new Animated.Value(0)),
},
headerTitle: navigation.getParam('title', ''),
});
<ScrollContainer title= "個人中心" navigation={this.props.navigation} scrollOffset={this.state.scrollOffset}>
<Header
onLayout={(e) => { this.setState({ scrollOffset: e.nativeEvent.layout.height - px2dp(18) }) }}
title="個人中心"
iconName="cog"
onPress={() => this.props.navigation.navigate('settings') }
/>
{this.renderUserInfo()}
{this.renderOptions()}
</ScrollContainer>
Properties
屬性 | 描述 | 型別 | 預設 |
---|---|---|---|
title | 導航欄標題 | PropTypes.string.isRequired |
標題 |
scrollOffset | 滑動距離閥值 | PropTypes.number.isRequired |
0 |
style | 樣式 | PropTypes.oneOfType([ PropTypes.object, PropTypes.number ]) |
{ flex: 1, backgroundColor: '#F7F7F7' } |
navigation | 導航屬性 | PropTypes.object.isRequired |
必填,否則無法控制導航,實現互動效果 |