Skip to content

Commit 665a9c5

Browse files
authored
Merge pull request #56 from bamlab/Jahans3-master
Jahans3 master
2 parents fc306a3 + fbd71dc commit 665a9c5

File tree

8 files changed

+766
-18
lines changed

8 files changed

+766
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/**/*
22
npm-debug.*
3+
.idea

README.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ The `HeaderImageScrollView` handle also the following props. None is required :
6161
| `maxOverlayOpacity` | `number` | `0.3` | Opacity of a black overlay on the header when in navbar mode | [example](https://github.com/bamlab/react-native-image-header-scroll-view-example/blob/3b9d2d0d7f71c6bf877e2d10cc65c9ab7e1b484d/src/Pages/TvShow.js#L96) |
6262
| `overlayColor` | `string` | `black` | Color of the overlay on the header | [example](https://github.com/bamlab/react-native-image-header-scroll-view-example/blob/master/src/Pages/Colors.js#L16) |
6363
| `useNativeDriver` | `boolean` | `false` | Use native driver for the animation for performance improvement. A few props are unsupported at the moment if `useNativeDriver=true` (`onScroll`, `ScrollComponent`, `renderTouchableFixedForeground`) | - |
64-
65-
64+
|`headerContainerStyle`|`Object`|`undefined`| Optional styles to be passed to the container of the header component|
65+
|`disableHeaderGrow`|`boolean`|`undefined`| Disable to grow effect on the header|
6666

6767
### Foreground
6868

@@ -73,6 +73,7 @@ The `HeaderImageScrollView` handle also the following props. None is required :
7373
| `foregroundParallaxRatio` | `number` | `1` | Ration for parallax effect of foreground when scrolling. If 2, the header goes up two times faster than the scroll | [example](https://github.com/bamlab/react-native-image-header-scroll-view-example/blob/master/src/Pages/Colors.js#L23) |
7474
| `fadeOutForeground` | `bool` | `false` | If set, add a fade out effect on the foreground when scroll up | [example](https://github.com/bamlab/react-native-image-header-scroll-view-example/blob/master/src/Pages/Colors.js#L13) |
7575
| `renderTouchableFixedForeground` | `function` | Empty view | Same as `renderFixedForeground` but allow to use touchable in it. [*Can cause performances issues on Android*](https://github.com/bamlab/react-native-image-header-scroll-view/issues/6)| [example](https://github.com/bamlab/react-native-image-header-scroll-view-example/blob/master/src/Pages/PullToRefresh.js#L45) |
76+
|`fixedForegroundContainerStyles`|`Object`|`undefined`| Optional styles to be passed to the container of the fixed foreground component|
7677

7778
### Mixed
7879

@@ -98,7 +99,39 @@ All of the properties of `View` are supported.
9899
| `onDisplay` | `function` | Called when the component finished to be displayed again. |
99100
| `onTouchTop` | `function` | Called when the Top of the component touch the Top of the ScrollView. (`onDisplay` + `onBeginHidden`) |
100101
| `onTouchBottom` | `function` | Called when the Bottom of the component touch the Top of the ScrollView. (`onHide` + `onBeginDisplayed`) |
101-
### Contributing
102+
103+
104+
105+
## FAQ
106+
107+
### How to remove the black image overlay
108+
109+
Just set the `maxOverlayOpacity` to `0`.
110+
111+
```jsx
112+
<HeaderImageScrollView
113+
minOverlayOpacity={0}
114+
maxOverlayOpacity={0}
115+
{/* ... */}
116+
/>
117+
118+
```
119+
120+
### How to remove the image zomming on scroll down
121+
122+
You have two solutions :
123+
124+
1. You can use the `disableHeaderGrow` props. It will keep the ios elastic scroll effect.
125+
2. You can also use the `bounces={false}` props [from the scroll view](https://facebook.github.io/react-native/docs/scrollview#bounces).
126+
127+
Results :
128+
129+
| `disableHeaderGrow` | `bounces={false}` |
130+
| ------------------- | ----------------- |
131+
![react-native-image-header-scroll-view demo disableHeaderGrow](./readmeAssets/demoDisableHeaderGrow.gif)|![react-native-image-header-scroll-view demo bounces](./readmeAssets/demoBounces.gif)
132+
133+
134+
## Contributing
102135

103136
All contributions are welcomed, that might be either adding new features, doing some refaco of the exisiting code or fixing bugs.
104137

@@ -107,8 +140,9 @@ All contributions are welcomed, that might be either adding new features, doing
107140
1. Fork the project & clone locally. Follow the initial setup here.
108141
2. Create a branch, naming it either a feature or bug: git checkout -b feature/that-new-feature or bug/fixing-that-bug
109142
3. Code and commit your changes. Write a good commit message. Best would be to use git [commitizen](https://github.com/commitizen/cz-cli)
110-
4. Push to the branch: git push origin feature/that-new-feature
111-
5. Create a pull request for your branch 🎉
143+
4. Test your changes in the [example repository](https://github.com/bamlab/react-native-image-header-scroll-view-example)
144+
5. Push to the branch: git push origin feature/that-new-feature
145+
6. Create a pull request for your branch 🎉
112146

113147

114148
## Other open-source modules by the folks at [BAM](http://github.com/bamlab)

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
"test": "npm run lint && flow",
99
"prettify": "prettier --write src/**.js"
1010
},
11-
"files": ["README.md", "LICENCE", "src", "readmeAssets"],
11+
"files": [
12+
"README.md",
13+
"LICENCE",
14+
"src",
15+
"readmeAssets"
16+
],
1217
"repository": {
1318
"type": "git",
1419
"url": "git+https://github.com/bamlab/react-native-image-header-scroll-view.git"

readmeAssets/demoBounces.gif

1.89 MB
Loading
2.5 MB
Loading

src/ImageHeaderScrollView.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ export type Props = ScrollViewProps & {
4343
scrollViewBackgroundColor: string,
4444
headerImage?: ?SourceProps,
4545
useNativeDriver: ?boolean,
46+
headerContainerStyle?: ?Object,
47+
fixedForegroundContainerStyles?: ?Object,
48+
disableHeaderGrow?: ?boolean,
4649
};
4750

4851
export type DefaultProps = {
@@ -73,6 +76,7 @@ class ImageHeaderScrollView extends Component<Props, State> {
7376

7477
static defaultProps: DefaultProps = {
7578
overlayColor: 'black',
79+
disableHeaderGrow: false,
7680
fadeOutForeground: false,
7781
foregroundParallaxRatio: 1,
7882
maxHeight: 125,
@@ -138,19 +142,25 @@ class ImageHeaderScrollView extends Component<Props, State> {
138142

139143
const headerTransformStyle = {
140144
height: this.props.maxHeight,
141-
transform: [{ scale: headerScale }],
145+
transform: !this.props.disableHeaderGrow ? [{ scale: headerScale }] : undefined,
142146
};
143147

144148
const overlayStyle = [
145149
styles.overlay,
146150
{ opacity: overlayOpacity, backgroundColor: this.props.overlayColor },
147151
];
148152

153+
const disableOverlay =
154+
this.props.minOverlayOpacity === this.props.maxOverlayOpacity &&
155+
this.props.maxOverlayOpacity === 0;
156+
149157
return (
150-
<Animated.View style={[styles.header, headerTransformStyle]}>
158+
<Animated.View style={[styles.header, headerTransformStyle, this.props.headerContainerStyle]}>
151159
{this.renderHeaderProps()}
152-
<Animated.View style={overlayStyle} />
153-
<View style={styles.fixedForeground}>{this.props.renderFixedForeground()}</View>
160+
{!disableOverlay && <Animated.View style={overlayStyle} />}
161+
<View style={[styles.fixedForeground, this.props.fixedForegroundContainerStyles]}>
162+
{this.props.renderFixedForeground()}
163+
</View>
154164
</Animated.View>
155165
);
156166
}
@@ -161,12 +171,10 @@ class ImageHeaderScrollView extends Component<Props, State> {
161171
outputRange: [0, -this.props.maxHeight * 2 * this.props.foregroundParallaxRatio],
162172
extrapolate: 'clamp',
163173
});
164-
const opacity = this.interpolateOnImageHeight([1, -0.3]);
165174

166175
const headerTransformStyle = {
167176
height: this.props.maxHeight,
168177
transform: [{ translateY: headerTranslate }],
169-
opacity: this.props.fadeOutForeground ? opacity : 1,
170178
};
171179

172180
if (!this.props.renderForeground) {
@@ -261,13 +269,17 @@ class ImageHeaderScrollView extends Component<Props, State> {
261269
backgroundColor: scrollViewBackgroundColor,
262270
},
263271
]}
264-
ref={ref => (this.container = ref)}
272+
ref={ref => {
273+
this.container = ref;
274+
}}
265275
onLayout={this.onContainerLayout}
266276
>
267277
{this.renderHeader()}
268278
<ScrollViewComponent
269-
ref={ref => (this.scrollViewRef = ref)}
270279
scrollEventThrottle={useNativeDriver ? 1 : 16}
280+
ref={ref => {
281+
this.scrollViewRef = ref;
282+
}}
271283
overScrollMode="never"
272284
{...scrollViewProps}
273285
contentContainerStyle={[
@@ -305,6 +317,7 @@ class ImageHeaderScrollView extends Component<Props, State> {
305317
}
306318
return responder.getScrollableNode();
307319
}
320+
308321
getInnerViewNode(): any {
309322
const responder = this.getScrollResponder();
310323
if (!responder) {

src/TriggeringView.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type Props = {
1212
onTouchBottom: Function,
1313
children?: React$Node,
1414
onLayout?: Function,
15+
bottomOffset?: number,
16+
topOffset?: number,
1517
};
1618

1719
type DefaultProps = {
@@ -21,6 +23,8 @@ type DefaultProps = {
2123
onDisplay: Function,
2224
onTouchTop: Function,
2325
onTouchBottom: Function,
26+
bottomOffset: number,
27+
topOffset: number,
2428
};
2529

2630
type State = {
@@ -55,6 +59,8 @@ class TriggeringView extends Component<Props, State> {
5559
onDisplay: () => {},
5660
onTouchTop: () => {},
5761
onTouchBottom: () => {},
62+
bottomOffset: 0,
63+
topOffset: 0,
5864
};
5965

6066
constructor(props: Props) {
@@ -104,21 +110,22 @@ class TriggeringView extends Component<Props, State> {
104110
};
105111

106112
triggerEvents(value: number, top: number, bottom: number) {
107-
if (!this.state.touched && value >= top) {
113+
const { bottomOffset, topOffset } = this.props;
114+
if (!this.state.touched && value >= top + topOffset) {
108115
this.setState({ touched: true });
109116
this.props.onBeginHidden();
110117
this.props.onTouchTop(true);
111-
} else if (this.state.touched && value < top) {
118+
} else if (this.state.touched && value < top + topOffset) {
112119
this.setState({ touched: false });
113120
this.props.onDisplay();
114121
this.props.onTouchTop(false);
115122
}
116123

117-
if (!this.state.hidden && value >= bottom) {
124+
if (!this.state.hidden && value >= bottom + bottomOffset) {
118125
this.setState({ hidden: true });
119126
this.props.onHide();
120127
this.props.onTouchBottom(true);
121-
} else if (this.state.hidden && value < bottom) {
128+
} else if (this.state.hidden && value < bottom + bottomOffset) {
122129
this.setState({ hidden: false });
123130
this.props.onBeginDisplayed();
124131
this.props.onTouchBottom(false);

0 commit comments

Comments
 (0)