Skip to content

Commit

Permalink
feat: Expose useNativeDriver as Container prop (#122)
Browse files Browse the repository at this point in the history
New prop: `useNativeDriver`, defaults to `false`.  
This prop allows turning on [the native driver](https://reactnative.dev/blog/2017/02/14/using-native-driver-for-animated) to animate the Modal component. Please be aware that the native driver may make the modal flash on Android (which is why we're defaulting it to `false`).
  • Loading branch information
SimpleCreations authored Sep 8, 2021
1 parent 97abf99 commit dd6d979
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ const styles = StyleSheet.create({
| onRequestClose | func | undefined | Callback invoked when the hardware back button on Android or the menu button on Apple TV is pressed |
| keyboardVerticalOffset | number | undefined | keyboardVerticalOffset for iOS |
| verticalButtons | bool | false | Renders button vertically |
| useNativeDriver | bool | false | Defines if animations should use native driver |
### Dialog.Input props
Expand Down
2 changes: 2 additions & 0 deletions src/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type DialogContainerProps = PropsWithChildren<{
onBackdropPress?: () => void;
onRequestClose?: () => void;
keyboardVerticalOffset?: number;
useNativeDriver?: boolean;
}>;

const DialogContainer: React.FC<DialogContainerProps> = (props) => {
Expand Down Expand Up @@ -146,6 +147,7 @@ DialogContainer.propTypes = {
verticalButtons: PropTypes.bool,
onBackdropPress: PropTypes.func,
keyboardVerticalOffset: PropTypes.number,
useNativeDriver: PropTypes.bool,
children: PropTypes.node.isRequired,
};

Expand Down
9 changes: 5 additions & 4 deletions src/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface ModalProps extends ReactNativeModalProps {
onHide?: () => void;
visible?: boolean;
contentStyle?: StyleProp<ViewStyle>;
useNativeDriver?: boolean;
}

interface ModalState {
Expand All @@ -77,12 +78,14 @@ export class Modal extends Component<ModalProps, ModalState> {
onHide: PropTypes.func,
visible: PropTypes.bool,
contentStyle: ViewPropTypes.style,
useNativeDriver: PropTypes.bool,
};

static defaultProps: Partial<ModalProps> = {
onBackdropPress: () => null,
onHide: () => null,
visible: false,
useNativeDriver: false,
};

state: ModalState = {
Expand Down Expand Up @@ -116,8 +119,7 @@ export class Modal extends Component<ModalProps, ModalState> {
this.setState({ visible: true, currentAnimation: "in" }, () => {
Animated.timing(this.animVal, {
easing: Easing.inOut(Easing.quad),
// Using native driver in the modal makes the content flash
useNativeDriver: false,
useNativeDriver: Boolean(this.props.useNativeDriver),
duration: MODAL_ANIM_DURATION,
toValue: 1,
}).start(() => {
Expand All @@ -130,8 +132,7 @@ export class Modal extends Component<ModalProps, ModalState> {
this.setState({ currentAnimation: "out" }, () => {
Animated.timing(this.animVal, {
easing: Easing.inOut(Easing.quad),
// Using native driver in the modal makes the content flash
useNativeDriver: false,
useNativeDriver: Boolean(this.props.useNativeDriver),
duration: MODAL_ANIM_DURATION,
toValue: 0,
}).start(() => {
Expand Down

0 comments on commit dd6d979

Please sign in to comment.