Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trigger fix #130

Merged
merged 3 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/expo/src/components/modals/FixedContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class FixedContent extends React.PureComponent {

render() {
return (
<Modalize ref={this.modal} adjustToContentHeight>
<Modalize ref={this.modal} scrollViewProps={{ scrollEnabled: false }} adjustToContentHeight>
{this.renderContent()}
</Modalize>
);
Expand Down
7 changes: 6 additions & 1 deletion examples/react-native-navigation/src/screens/FixedContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ export class FixedContent extends React.PureComponent {

render() {
return (
<Modalize ref={this.modal} onClosed={this.onClosed} adjustToContentHeight>
<Modalize
ref={this.modal}
onClosed={this.onClosed}
scrollViewProps={{ scrollEnabled: false }}
adjustToContentHeight
>
{this.renderContent()}
</Modalize>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class FixedContent extends React.PureComponent {

render() {
return (
<Modalize ref={this.modal} adjustToContentHeight>
<Modalize ref={this.modal} scrollViewProps={{ scrollEnabled: false }} adjustToContentHeight>
{this.renderContent()}
</Modalize>
);
Expand Down
43 changes: 4 additions & 39 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
private snaps: number[] = [];
private snapEnd: number;
private beginScrollYValue: number = 0;
private contentAlreadyCalculated: boolean = false;
private beginScrollY: Animated.Value = new Animated.Value(0);
private dragY: Animated.Value = new Animated.Value(0);
private translateY: Animated.Value = new Animated.Value(screenHeight);
Expand Down Expand Up @@ -158,17 +157,13 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
}

public open = (): void => {
const { adjustToContentHeight, onOpen } = this.props;
const { onOpen } = this.props;

if (onOpen) {
onOpen();
}

if (!adjustToContentHeight || this.contentAlreadyCalculated) {
this.onAnimateOpen();
} else {
this.setState({ isVisible: true });
}
this.onAnimateOpen();
};

public close = (dest: 'alwaysOpen' | 'default' = 'default'): void => {
Expand Down Expand Up @@ -375,36 +370,6 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
});
};

private onContentViewLayout = ({ nativeEvent }: LayoutChangeEvent): void => {
const { adjustToContentHeight, snapPoint, alwaysOpen } = this.props;
const { contentHeight, modalHeight } = this.state;

if (
!adjustToContentHeight ||
(modalHeight || 0) <= nativeEvent.layout.height ||
snapPoint ||
this.contentAlreadyCalculated
) {
if ((modalHeight || 0) <= nativeEvent.layout.height) {
this.onAnimateOpen(alwaysOpen);
}

return;
}

// @todo: modalHeight should be equal to the nativeEvent's height,
// and not to the state's value which is 0 at the first mount
this.setState(
{
contentHeight: nativeEvent.layout.height || contentHeight,
},
() => {
this.contentAlreadyCalculated = true;
this.onAnimateOpen();
},
);
};

private onHandleComponent = ({ nativeEvent }: PanGestureHandlerStateChangeEvent): void => {
if (nativeEvent.oldState === State.BEGAN) {
this.beginScrollY.setValue(0);
Expand Down Expand Up @@ -611,7 +576,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
{ useNativeDriver: false },
),
scrollEventThrottle: 16,
onLayout: this.onContentViewLayout,
keyboardDismissMode,
};

if (flatListProps) {
Expand All @@ -623,7 +588,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
}

return (
<Animated.ScrollView {...opts} {...scrollViewProps} keyboardDismissMode={keyboardDismissMode}>
<Animated.ScrollView {...opts} {...scrollViewProps}>
{children}
</Animated.ScrollView>
);
Expand Down