Skip to content

Commit 27da5c1

Browse files
author
Carol Chiew
committed
Update readme
1 parent c824e8e commit 27da5c1

File tree

2 files changed

+126
-98
lines changed

2 files changed

+126
-98
lines changed

README.md

+74-42
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,87 @@ $ npm i react-native-parallax-header --save
2525
![iPhone 8](https://i.gyazo.com/eebeff28c7df7b0233fabb9cf2a9c5dc.gif)
2626

2727
## Example
28+
Refer to [TestParallax](https://github.com/kyaroru/TestParallax) for working example
2829
```jsx
29-
import Icon from 'react-native-vector-icons/MaterialIcons';
30+
import React from 'react';
31+
import {
32+
StyleSheet,
33+
View,
34+
Text,
35+
StatusBar,
36+
Dimensions,
37+
TouchableOpacity,
38+
} from 'react-native';
3039
import ReactNativeParallaxHeader from 'react-native-parallax-header';
3140

41+
const {height: SCREEN_HEIGHT} = Dimensions.get('window');
42+
3243
const IS_IPHONE_X = SCREEN_HEIGHT === 812 || SCREEN_HEIGHT === 896;
3344
const STATUS_BAR_HEIGHT = Platform.OS === 'ios' ? (IS_IPHONE_X ? 44 : 20) : 0;
3445
const HEADER_HEIGHT = Platform.OS === 'ios' ? (IS_IPHONE_X ? 88 : 64) : 64;
3546
const NAV_BAR_HEIGHT = HEADER_HEIGHT - STATUS_BAR_HEIGHT;
3647

37-
const images = {
38-
background: require('../img/test.jpg'), // Put your own image here
48+
const renderNavBar = () => (
49+
<View style={styles.navContainer}>
50+
<View style={styles.statusBar} />
51+
<View style={styles.navBar}>
52+
<TouchableOpacity style={styles.iconLeft} onPress={() => {}}>
53+
<Text style={{color: 'white'}}>About</Text>
54+
</TouchableOpacity>
55+
<TouchableOpacity style={styles.iconRight} onPress={() => {}}>
56+
<Text style={{color: 'white'}}>Me</Text>
57+
</TouchableOpacity>
58+
</View>
59+
</View>
60+
);
61+
62+
const renderContent = () => {
63+
return (
64+
<View style={styles.body}>
65+
{Array.from(Array(30).keys()).map((i) => (
66+
<View
67+
key={i}
68+
style={{padding: 15, alignItems: 'center', justifyContent: 'center'}}>
69+
<Text>Item {i + 1}</Text>
70+
</View>
71+
))}
72+
</View>
73+
);
74+
};
75+
76+
const title = () => {
77+
return (
78+
<View style={styles.body}>
79+
<Text style={{color: 'white', fontSize: 25}}>Parallax Header</Text>
80+
</View>
81+
);
82+
};
83+
84+
const App = () => {
85+
return (
86+
<>
87+
<StatusBar barStyle="dark-content" />
88+
<ReactNativeParallaxHeader
89+
headerMinHeight={HEADER_HEIGHT}
90+
headerMaxHeight={250}
91+
extraScrollHeight={20}
92+
navbarColor="#3498db"
93+
titleStyle={styles.titleStyle}
94+
title={title()}
95+
backgroundImage={require('./bg.png')}
96+
backgroundImageScale={1.2}
97+
renderNavBar={renderNavBar}
98+
renderContent={renderContent}
99+
containerStyle={styles.container}
100+
contentContainerStyle={styles.contentContainer}
101+
innerContainerStyle={styles.container}
102+
scrollViewProps={{
103+
onScrollBeginDrag: () => console.log('onScrollBeginDrag'),
104+
onScrollEndDrag: () => console.log('onScrollEndDrag'),
105+
}}
106+
/>
107+
</>
108+
);
39109
};
40110

41111
const styles = StyleSheet.create({
@@ -67,45 +137,7 @@ const styles = StyleSheet.create({
67137
},
68138
});
69139

70-
renderNavBar = () => (
71-
<View style={styles.navContainer}>
72-
<View style={styles.statusBar} />
73-
<View style={styles.navBar}>
74-
<TouchableOpacity style={styles.iconLeft} onPress={() => {}}>
75-
<Icon name="add" size={25} color="#fff" />
76-
</TouchableOpacity>
77-
<TouchableOpacity style={styles.iconRight} onPress={() => {}}>
78-
<Icon name="search" size={25} color="#fff" />
79-
</TouchableOpacity>
80-
</View>
81-
</View>
82-
)
83-
84-
render() {
85-
return (
86-
<View style={styles.container}>
87-
<ReactNativeParallaxHeader
88-
headerMinHeight={HEADER_HEIGHT}
89-
headerMaxHeight={250}
90-
extraScrollHeight={20}
91-
navbarColor="#3498db"
92-
title="Parallax Header ~"
93-
titleStyle={styles.titleStyle}
94-
backgroundImage={images.background}
95-
backgroundImageScale={1.2}
96-
renderNavBar={this.renderNavBar}
97-
renderContent={this.renderContent}
98-
containerStyle={styles.container}
99-
contentContainerStyle={styles.contentContainer}
100-
innerContainerStyle={styles.container}
101-
scrollViewProps={{
102-
onScrollBeginDrag: () => console.log('onScrollBeginDrag'),
103-
onScrollEndDrag: () => console.log('onScrollEndDrag'),
104-
}}
105-
/>
106-
</View>
107-
);
108-
}
140+
export default App;
109141
```
110142

111143
## API Usage

0 commit comments

Comments
 (0)