Skip to content

Commit dc34b40

Browse files
committed
Merge branch 'master' of https://github.com/Jahans3/react-native-image-header-scroll-view into Jahans3-master
* 'master' of https://github.com/Jahans3/react-native-image-header-scroll-view: (23 commits) v0.0.85 use animated overflow view for header add fixedForegroundContainerStyles prop v0.0.83 revert overflow changes v0.0.82 add new overflow view, bump package v0.0.81 v0.0.8 add more animated overflow views use overflow views add bottomOffset prop to triggeringview v0.0.6 dont fade out foreground v0.0.5 move ref v0.0.4 pass ref callback always define transform version + package name ...
2 parents fc306a3 + ba5f3f2 commit dc34b40

7 files changed

Lines changed: 4473 additions & 16 deletions

File tree

.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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ 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|
66+
|`disableOverlay`|`boolean`|`undefined`|Disable the image overlay|
6667

6768
### Foreground
6869

package.json

Lines changed: 9 additions & 2 deletions
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"
@@ -42,7 +47,9 @@
4247
"react-native": ">=0.20.0"
4348
},
4449
"dependencies": {
45-
"prop-types": "^15.6.0"
50+
"prop-types": "^15.6.0",
51+
"react-native-image-header-scroll-view-ep": "^0.0.8",
52+
"react-native-view-overflow": "^0.0.3"
4653
},
4754
"eslintConfig": {
4855
"extends": "bambi/native"

src/ImageHeaderScrollView.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import React, { Component } from 'react';
33
import PropTypes from 'prop-types';
44
import { Animated, ScrollView, StyleSheet, View, Image, Dimensions } from 'react-native';
5+
import OverflowView from 'react-native-view-overflow';
56
import type { ViewProps } from 'ViewPropTypes';
67
import type { FlatList, SectionList, ListView } from 'react-native';
78

9+
const AnimatedOverflow = Animated.createAnimatedComponent(OverflowView);
10+
811
type ScrollViewProps = {
912
onScroll?: ?Function,
1013
style?: $PropertyType<ViewProps, 'style'>,
@@ -43,6 +46,9 @@ export type Props = ScrollViewProps & {
4346
scrollViewBackgroundColor: string,
4447
headerImage?: ?SourceProps,
4548
useNativeDriver: ?boolean,
49+
headerContainerStyle?: ?Object,
50+
disableHeaderGrow?: ?boolean,
51+
disableOverlay?: ?boolean,
4652
};
4753

4854
export type DefaultProps = {
@@ -73,6 +79,7 @@ class ImageHeaderScrollView extends Component<Props, State> {
7379

7480
static defaultProps: DefaultProps = {
7581
overlayColor: 'black',
82+
disableHeaderGrow: false,
7683
fadeOutForeground: false,
7784
foregroundParallaxRatio: 1,
7885
maxHeight: 125,
@@ -138,7 +145,7 @@ class ImageHeaderScrollView extends Component<Props, State> {
138145

139146
const headerTransformStyle = {
140147
height: this.props.maxHeight,
141-
transform: [{ scale: headerScale }],
148+
transform: !this.props.disableHeaderGrow ? [{ scale: headerScale }] : undefined,
142149
};
143150

144151
const overlayStyle = [
@@ -147,11 +154,15 @@ class ImageHeaderScrollView extends Component<Props, State> {
147154
];
148155

149156
return (
150-
<Animated.View style={[styles.header, headerTransformStyle]}>
157+
<AnimatedOverflow
158+
style={[styles.header, headerTransformStyle, this.props.headerContainerStyle]}
159+
>
151160
{this.renderHeaderProps()}
152-
<Animated.View style={overlayStyle} />
153-
<View style={styles.fixedForeground}>{this.props.renderFixedForeground()}</View>
154-
</Animated.View>
161+
{!this.props.disableOverlay && <Animated.View style={overlayStyle} />}
162+
<View style={[styles.fixedForeground, this.props.fixedForegroundContainerStyles]}>
163+
{this.props.renderFixedForeground()}
164+
</View>
165+
</AnimatedOverflow>
155166
);
156167
}
157168

@@ -161,12 +172,10 @@ class ImageHeaderScrollView extends Component<Props, State> {
161172
outputRange: [0, -this.props.maxHeight * 2 * this.props.foregroundParallaxRatio],
162173
extrapolate: 'clamp',
163174
});
164-
const opacity = this.interpolateOnImageHeight([1, -0.3]);
165175

166176
const headerTransformStyle = {
167177
height: this.props.maxHeight,
168178
transform: [{ translateY: headerTranslate }],
169-
opacity: this.props.fadeOutForeground ? opacity : 1,
170179
};
171180

172181
if (!this.props.renderForeground) {
@@ -242,6 +251,7 @@ class ImageHeaderScrollView extends Component<Props, State> {
242251
onScroll,
243252
scrollViewBackgroundColor,
244253
useNativeDriver,
254+
getScrollViewRef,
245255
...scrollViewProps
246256
} = this.props;
247257
/* eslint-enable no-unused-vars */
@@ -261,13 +271,21 @@ class ImageHeaderScrollView extends Component<Props, State> {
261271
backgroundColor: scrollViewBackgroundColor,
262272
},
263273
]}
264-
ref={ref => (this.container = ref)}
274+
ref={ref => {
275+
this.container = ref;
276+
}}
265277
onLayout={this.onContainerLayout}
266278
>
267279
{this.renderHeader()}
268280
<ScrollViewComponent
269-
ref={ref => (this.scrollViewRef = ref)}
270281
scrollEventThrottle={useNativeDriver ? 1 : 16}
282+
ref={ref => {
283+
if (getScrollViewRef) {
284+
getScrollViewRef(ref);
285+
}
286+
287+
this.scrollViewRef = ref;
288+
}}
271289
overScrollMode="never"
272290
{...scrollViewProps}
273291
contentContainerStyle={[
@@ -305,6 +323,7 @@ class ImageHeaderScrollView extends Component<Props, State> {
305323
}
306324
return responder.getScrollableNode();
307325
}
326+
308327
getInnerViewNode(): any {
309328
const responder = this.getScrollResponder();
310329
if (!responder) {

src/TriggeringView.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Props = {
1212
onTouchBottom: Function,
1313
children?: React$Node,
1414
onLayout?: Function,
15+
bottomOffset?: number,
1516
};
1617

1718
type DefaultProps = {
@@ -21,6 +22,7 @@ type DefaultProps = {
2122
onDisplay: Function,
2223
onTouchTop: Function,
2324
onTouchBottom: Function,
25+
bottomOffset: number,
2426
};
2527

2628
type State = {
@@ -30,7 +32,7 @@ type State = {
3032

3133
type Context = {
3234
scrollPageY?: number,
33-
scrollY: Animated.Value,
35+
scrollY: typeof Animated.Value,
3436
};
3537

3638
class TriggeringView extends Component<Props, State> {
@@ -55,6 +57,7 @@ class TriggeringView extends Component<Props, State> {
5557
onDisplay: () => {},
5658
onTouchTop: () => {},
5759
onTouchBottom: () => {},
60+
bottomOffset: 0,
5861
};
5962

6063
constructor(props: Props) {
@@ -114,11 +117,11 @@ class TriggeringView extends Component<Props, State> {
114117
this.props.onTouchTop(false);
115118
}
116119

117-
if (!this.state.hidden && value >= bottom) {
120+
if (!this.state.hidden && value >= bottom + this.props.bottomOffset) {
118121
this.setState({ hidden: true });
119122
this.props.onHide();
120123
this.props.onTouchBottom(true);
121-
} else if (this.state.hidden && value < bottom) {
124+
} else if (this.state.hidden && value < bottom + this.props.bottomOffset) {
122125
this.setState({ hidden: false });
123126
this.props.onBeginDisplayed();
124127
this.props.onTouchBottom(false);

0 commit comments

Comments
 (0)