Skip to content

Commit

Permalink
remove PropsType and use last version of flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Nhacsam committed Nov 1, 2017
1 parent 4962b57 commit b6cf798
Show file tree
Hide file tree
Showing 6 changed files with 2,992 additions and 143 deletions.
17 changes: 6 additions & 11 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@
.*/node_modules/react-navigation

; Do not remove all example to have react-native
.*/example/main.js
.*/example/Pages/.*

; Remove duplication between example and .
.*/example/node_modules/fbjs/

; Remove not passing libs
.*/example/node_modules/react-native-tab-view/
.*/example/.*

[include]

Expand All @@ -44,14 +37,16 @@ module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|we

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState
suppress_type=$FixMe

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-7]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-7]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-3]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-3]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

unsafe.enable_getters_and_setters=true

[version]
^0.47.0
^0.53.0
7 changes: 4 additions & 3 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3338,11 +3338,12 @@ [email protected]:
dependencies:
react-native-dismiss-keyboard "1.0.0"

react-native-image-header-scroll-view@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/react-native-image-header-scroll-view/-/react-native-image-header-scroll-view-0.6.1.tgz#84beba8acbef69761a4e8c15bb0c18a011598d11"
react-native-image-header-scroll-view@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/react-native-image-header-scroll-view/-/react-native-image-header-scroll-view-0.6.2.tgz#ed4a367bbf4d89c984faca833073509ce198c13b"
dependencies:
lodash "^4.17.4"
prop-types "^15.5.10"

react-native-tab-view@^0.0.65:
version "0.0.65"
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-prettier": "2.1.2",
"eslint-plugin-react": "^6.10.0",
"flow-bin": "^0.47.0",
"flow-bin": "^0.53.0",
"prettier": "^1.5.3",
"react": "16.0.0-alpha.12"
"react": "16.0.0-beta.5",
"react-native": "0.49.5"
},
"peerDependencies": {
"react": ">=15.3.1",
"react-native": ">=0.20.0"
},
"dependencies": {
"lodash": "^4.17.4",
"prop-types": "^15.5.10"
"lodash": "^4.17.4"
}
}
55 changes: 40 additions & 15 deletions src/ImageHeaderScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Animated, ScrollView, StyleSheet, View } from 'react-native';
import _ from 'lodash';

export type Props = {
children: React.Element<any>,
children: React$Element<any>,
childrenStyle: any,
overlayColor: string,
fadeOutForeground: boolean,
Expand All @@ -14,10 +14,10 @@ export type Props = {
maxOverlayOpacity: number,
minHeight: number,
minOverlayOpacity: number,
renderFixedForeground: () => React.Element<any>,
renderForeground: () => React.Element<any>,
renderHeader: () => React.Element<any>,
renderTouchableFixedForeground: () => React.Element<any>,
renderFixedForeground: () => React$Element<any>,
renderForeground: () => React$Element<any>,
renderHeader: () => React$Element<any>,
renderTouchableFixedForeground: () => React$Element<any>,
};

export type DefaultProps = {
Expand All @@ -28,19 +28,19 @@ export type DefaultProps = {
maxOverlayOpacity: number,
minHeight: number,
minOverlayOpacity: number,
renderFixedForeground: () => React.Element<any>,
renderForeground: () => React.Element<any>,
renderHeader: () => React.Element<any>,
renderFixedForeground: () => React$Element<any>,
renderForeground: () => React$Element<any>,
renderHeader: () => React$Element<any>,
};

export type State = {
scrollY: Animated.Value,
pageY: number,
};

class ImageHeaderScrollView extends Component<DefaultProps, Props, State> {
container: *;
scrollViewRef: ScrollView;
class ImageHeaderScrollView extends Component<Props, State> {
container: ?any; // @see https://github.com/facebook/react-native/issues/15955
scrollViewRef: ?any; // @see https://github.com/facebook/react-native/issues/15955
state: State;

static defaultProps: DefaultProps = {
Expand Down Expand Up @@ -76,19 +76,37 @@ class ImageHeaderScrollView extends Component<DefaultProps, Props, State> {
* with any component that expects a `ScrollView`.
*/
getScrollResponder() {
if (!this.scrollViewRef) {
return;
}
return this.scrollViewRef.getScrollResponder();
}
getScrollableNode() {
return this.getScrollResponder().getScrollableNode();
const responder = this.getScrollResponder();
if (!responder) {
return;
}
return responder.getScrollableNode();
}
getInnerViewNode() {
return this.getScrollResponder().getInnerViewNode();
const responder = this.getScrollResponder();
if (!responder) {
return;
}
return responder.getInnerViewNode();
}
setNativeProps(props: Props) {
if (!this.scrollViewRef) {
return;
}
this.scrollViewRef.setNativeProps(props);
}
scrollTo(...args: *) {
this.getScrollResponder().scrollTo(...args);
const responder = this.getScrollResponder();
if (!responder) {
return;
}
responder.scrollTo(...args);
}

interpolateOnImageHeight(outputRange: Array<number>) {
Expand Down Expand Up @@ -178,6 +196,13 @@ class ImageHeaderScrollView extends Component<DefaultProps, Props, State> {
);
}

onContainerLayout = () => {
if (!this.container) {
return;
}
this.container.measureInWindow((x, y) => this.setState(() => ({ pageY: y })));
};

render() {
const {
children,
Expand Down Expand Up @@ -209,7 +234,7 @@ class ImageHeaderScrollView extends Component<DefaultProps, Props, State> {
<View
style={styles.container}
ref={ref => (this.container = ref)}
onLayout={() => this.container.measureInWindow((x, y) => this.setState({ pageY: y }))}
onLayout={this.onContainerLayout}
>
{this.renderHeader()}
<Animated.View style={[styles.container, { transform: [{ translateY: topMargin }] }]}>
Expand Down
105 changes: 62 additions & 43 deletions src/TriggeringView.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
// @flow weak
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { View, Animated } from 'react-native';
import _ from 'lodash';

class TriggeringView extends Component<*, *, *> {
type Props = {
onBeginHidden: Function,
onHide: Function,
onBeginDisplayed: Function,
onDisplay: Function,
onTouchTop: Function,
onTouchBottom: Function,
children?: React$Node,
};

type DefaultProps = {
onBeginHidden: Function,
onHide: Function,
onBeginDisplayed: Function,
onDisplay: Function,
onTouchTop: Function,
onTouchBottom: Function,
};

type State = {
touched: boolean,
hidden: boolean,
};

type Context = {
scrollPageY?: number,
scrollY: Animated.Value,
};

class TriggeringView extends Component<Props, State> {
initialPageY: number;
listenerId: number;
ref: *;
listenerId: string;
ref: ?any; // @see https://github.com/facebook/react-native/issues/15955
height: number;
context: Context;

onScroll: Function;
onRef: Function;
onLayout: Function;
state: State = {
touched: false,
hidden: false,
};

static defaultProps: DefaultProps = {
onBeginHidden: () => {},
onHide: () => {},
onBeginDisplayed: () => {},
onDisplay: () => {},
onTouchTop: () => {},
onTouchBottom: () => {},
};

constructor(props) {
super(props);
this.state = {
touched: false,
hidden: false,
};
this.initialPageY = 0;
this.onScroll = this._onScroll.bind(this);
this.onRef = this._onRef.bind(this);
this.onLayout = this._onLayout.bind(this);
}

componentWillMount() {
Expand All @@ -41,40 +76,46 @@ class TriggeringView extends Component<*, *, *> {
nextContext.scrollY.addListener(this.onScroll);
}

_onRef(ref) {
onRef = ref => {
this.ref = ref;
}
};

_onLayout(e) {
onLayout = e => {
if (!this.ref) {
return;
}
const layout = e.nativeEvent.layout;
this.height = layout.height;
this.ref.measure((x, y, width, height, pageX, pageY) => {
this.initialPageY = pageY;
});
}
};

_onScroll(event) {
onScroll = event => {
if (!this.context.scrollPageY) {
return;
}
const pageY = this.initialPageY - event.value;
this.triggerEvents(this.context.scrollPageY, pageY, pageY + this.height);
}
};

triggerEvents(value, top, bottom) {
if (!this.state.touched && value >= top) {
this.setState({ touched: true });
this.setState(() => ({ touched: true }));
this.props.onBeginHidden();
this.props.onTouchTop(true);
} else if (this.state.touched && value < top) {
this.setState({ touched: false });
this.setState(() => ({ touched: false }));
this.props.onDisplay();
this.props.onTouchTop(false);
}

if (!this.state.hidden && value >= bottom) {
this.setState({ hidden: true });
this.setState(() => ({ hidden: true }));
this.props.onHide();
this.props.onTouchBottom(true);
} else if (this.state.hidden && value < bottom) {
this.setState({ hidden: false });
this.setState(() => ({ hidden: false }));
this.props.onBeginDisplayed();
this.props.onTouchBottom(false);
}
Expand All @@ -89,27 +130,5 @@ class TriggeringView extends Component<*, *, *> {
);
}
}
TriggeringView.propTypes = {
onBeginHidden: PropTypes.func,
onHide: PropTypes.func,
onBeginDisplayed: PropTypes.func,
onDisplay: PropTypes.func,
onTouchTop: PropTypes.func,
onTouchBottom: PropTypes.func,
};

TriggeringView.defaultProps = {
onBeginHidden: () => {},
onHide: () => {},
onBeginDisplayed: () => {},
onDisplay: () => {},
onTouchTop: () => {},
onTouchBottom: () => {},
};

TriggeringView.contextTypes = {

This comment has been minimized.

Copy link
@blackneck

blackneck Nov 14, 2017

Seems like without this lines onHide or onDisplay methods are not called any more

This comment has been minimized.

Copy link
@Nhacsam

Nhacsam Nov 16, 2017

Author Contributor

This comment has been minimized.

Copy link
@blackneck

blackneck Nov 16, 2017

Do you check it?
for me without contextTypes child views are not receive the context from HeaderImageScrollView

This comment has been minimized.

Copy link
@Nhacsam

Nhacsam Feb 4, 2018

Author Contributor
scrollY: PropTypes.instanceOf(Animated.Value),
scrollPageY: PropTypes.number,
};

export default TriggeringView;
Loading

0 comments on commit b6cf798

Please sign in to comment.