Skip to content

Commit

Permalink
feat: simplified and fixed changing of the adjustToContentHeight prop (
Browse files Browse the repository at this point in the history
…#166)

* fix: changing adjustToContentHeight prop

* fix: useNativeDriver TS errors after upgrading to RN 0.62

* add: todo to remove animated ref getNode method for RN >= 0.62

* fix: type of dest argument for close method

* fix: added type for untyped variable

* fix: remove optional for useNativeDriver prop

* fix: scrollTo compatibility with new RN versions
  • Loading branch information
xxsnakerxx authored Apr 4, 2020
1 parent 16781a7 commit 0c5d908
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
21 changes: 11 additions & 10 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
keyboardToggle: false,
keyboardHeight: 0,
disableScroll: props.alwaysOpen ? true : undefined,
adjust: props.adjustToContentHeight,
};

this.beginScrollY.addListener(({ value }) => (this.beginScrollYValue = value));
Expand All @@ -168,7 +167,6 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
if (nextAdjust !== adjustToContentHeight) {
this.setState({
modalHeight: nextAdjust ? undefined : this.initialComputedModalHeight,
adjust: nextAdjust,
});
}
}
Expand All @@ -189,7 +187,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
this.onAnimateOpen(alwaysOpen, dest);
};

public close = (dest: TClose = 'default'): void => {
public close = (dest?: TClose): void => {
const { onClose } = this.props;

if (onClose) {
Expand All @@ -201,10 +199,14 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C

public scrollTo = (...args: Parameters<ScrollView['scrollTo']>): void => {
if (this.contentView.current) {
(this.contentView.current as any)
.getNode()
.getScrollResponder()
.scrollTo(...args);
const ref = (this.contentView.current as any);

// since RN 0.62 the getNode call has been deprecated
const scrollResponder = ref.getScrollResponder
? ref.getScrollResponder()
: ref.getNode().getScrollResponder();

scrollResponder.scrollTo(...args);
}
};

Expand Down Expand Up @@ -605,7 +607,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
const diff = Math.abs(translationY / (this.initialComputedModalHeight - offset));
const y = translationY < 0 ? diff : 1 - diff;

let value;
let value: number;

if (this.modalPosition === 'initial' && translationY > 0) {
value = 0;
Expand Down Expand Up @@ -717,8 +719,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C

private renderChildren = (): React.ReactNode => {
const { adjustToContentHeight, panGestureEnabled } = this.props;
const { adjust } = this.state;
const style = !adjustToContentHeight && adjust ? s.content__container : s.content__adjustHeight;
const style = adjustToContentHeight ? s.content__adjustHeight : s.content__container;

return (
<PanGestureHandler
Expand Down
7 changes: 1 addition & 6 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export interface IProps<FlatListItem = any, SectionListItem = any> {
* Use the native thread to execute the animations.
* @default true
*/
useNativeDriver?: boolean;
useNativeDriver: boolean;

/**
* Object to change the open animations
Expand Down Expand Up @@ -306,9 +306,4 @@ export interface IState {
* Store height of the keyboard.
*/
keyboardHeight: number;

/**
* Store if the modal is using adjustToContentHeight props
*/
adjust: boolean | undefined;
}
3 changes: 3 additions & 0 deletions src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ export default StyleSheet.create({

content__container: {
flex: 1,
flexGrow: 1,
flexShrink: 1,
},

content__adjustHeight: {
flex: 0,
flexGrow: 0,
flexShrink: 1,
},
Expand Down

0 comments on commit 0c5d908

Please sign in to comment.