-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[TS Migration] Migrate withWindowDimensions and Modal directories to TypeScript #30338
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
Changes from all commits
eebfbf1
8213caa
cf613ad
408ef25
1c1d092
118415e
4c18fc0
c016d84
5f3968d
ffa9d70
a437818
7a637b9
7385968
c26a716
a1adc37
bc5c041
673d120
2d7d45b
a75557f
595c90d
da8b083
a6287ed
3dfe00b
f4afdb4
8082b7c
a5e8a58
20e80d1
434e472
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,18 @@ | ||
| import React from 'react'; | ||
| import withWindowDimensions from '@components/withWindowDimensions'; | ||
| import BaseModal from './BaseModal'; | ||
| import {defaultProps, propTypes} from './modalPropTypes'; | ||
| import BaseModalProps from './types'; | ||
|
|
||
| function Modal(props) { | ||
| function Modal({children, ...rest}: BaseModalProps) { | ||
| return ( | ||
| <BaseModal | ||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| {...props} | ||
| {...rest} | ||
| > | ||
| {props.children} | ||
| {children} | ||
| </BaseModal> | ||
| ); | ||
| } | ||
|
|
||
| Modal.propTypes = propTypes; | ||
| Modal.defaultProps = defaultProps; | ||
| Modal.displayName = 'Modal'; | ||
| export default withWindowDimensions(Modal); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,13 +5,13 @@ import * as StyleUtils from '@styles/StyleUtils'; | |
| import themeColors from '@styles/themes/default'; | ||
| import CONST from '@src/CONST'; | ||
| import BaseModal from './BaseModal'; | ||
| import {defaultProps, propTypes} from './modalPropTypes'; | ||
| import BaseModalProps from './types'; | ||
|
|
||
| function Modal(props) { | ||
| const [previousStatusBarColor, setPreviousStatusBarColor] = useState(); | ||
| function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = () => {}, children, ...rest}: BaseModalProps) { | ||
| const [previousStatusBarColor, setPreviousStatusBarColor] = useState<string>(); | ||
|
|
||
| const setStatusBarColor = (color = themeColors.appBG) => { | ||
| if (!props.fullscreen) { | ||
| if (!fullscreen) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -20,33 +20,37 @@ function Modal(props) { | |
|
|
||
| const hideModal = () => { | ||
| setStatusBarColor(previousStatusBarColor); | ||
| props.onModalHide(); | ||
| onModalHide(); | ||
| }; | ||
|
|
||
| const showModal = () => { | ||
| const statusBarColor = StatusBar.getBackgroundColor(); | ||
| const isFullScreenModal = | ||
| props.type === CONST.MODAL.MODAL_TYPE.CENTERED || props.type === CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE || props.type === CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED; | ||
| setPreviousStatusBarColor(statusBarColor); | ||
| // If it is a full screen modal then match it with appBG, otherwise we use the backdrop color | ||
| setStatusBarColor(isFullScreenModal ? themeColors.appBG : StyleUtils.getThemeBackgroundColor(statusBarColor)); | ||
| props.onModalShow(); | ||
|
|
||
| const isFullScreenModal = type === CONST.MODAL.MODAL_TYPE.CENTERED || type === CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE || type === CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED; | ||
|
|
||
| if (statusBarColor) { | ||
| setPreviousStatusBarColor(statusBarColor); | ||
| // If it is a full screen modal then match it with appBG, otherwise we use the backdrop color | ||
| setStatusBarColor(isFullScreenModal ? themeColors.appBG : StyleUtils.getThemeBackgroundColor(statusBarColor)); | ||
| } | ||
|
|
||
| onModalShow?.(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this syntax work for a method? call the method if it is not null?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignores when
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly! It's very useful and you can also use it to safely access arrays i.e. lets say you have a variable
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
| }; | ||
|
|
||
| return ( | ||
| <BaseModal | ||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| {...props} | ||
| {...rest} | ||
| onModalHide={hideModal} | ||
| onModalShow={showModal} | ||
| avoidKeyboard={false} | ||
| fullscreen={fullscreen} | ||
| type={type} | ||
| > | ||
| {props.children} | ||
| {children} | ||
| </BaseModal> | ||
| ); | ||
| } | ||
|
|
||
| Modal.propTypes = propTypes; | ||
| Modal.defaultProps = defaultProps; | ||
| Modal.displayName = 'Modal'; | ||
| export default withWindowDimensions(Modal); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import {ViewStyle} from 'react-native'; | ||
| import {ModalProps} from 'react-native-modal'; | ||
| import {ValueOf} from 'type-fest'; | ||
| import {WindowDimensionsProps} from '@components/withWindowDimensions/types'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| type PopoverAnchorPosition = { | ||
| top?: number; | ||
| right?: number; | ||
| bottom?: number; | ||
| left?: number; | ||
| }; | ||
|
|
||
| type BaseModalProps = WindowDimensionsProps & | ||
| ModalProps & { | ||
| /** Decides whether the modal should cover fullscreen. FullScreen modal has backdrop */ | ||
| fullscreen?: boolean; | ||
|
|
||
| /** Should we close modal on outside click */ | ||
| shouldCloseOnOutsideClick?: boolean; | ||
|
|
||
| /** Should we announce the Modal visibility changes? */ | ||
| shouldSetModalVisibility?: boolean; | ||
|
|
||
| /** Callback method fired when the user requests to close the modal */ | ||
| onClose: () => void; | ||
|
|
||
| /** State that determines whether to display the modal or not */ | ||
| isVisible: boolean; | ||
|
|
||
| /** Callback method fired when the user requests to submit the modal content. */ | ||
| onSubmit?: () => void; | ||
|
|
||
| /** Callback method fired when the modal is hidden */ | ||
| onModalHide?: () => void; | ||
|
|
||
| /** Callback method fired when the modal is shown */ | ||
| onModalShow?: () => void; | ||
|
|
||
| /** Style of modal to display */ | ||
| type?: ValueOf<typeof CONST.MODAL.MODAL_TYPE>; | ||
|
|
||
| /** The anchor position of a popover modal. Has no effect on other modal types. */ | ||
| popoverAnchorPosition?: PopoverAnchorPosition; | ||
|
|
||
| outerStyle?: ViewStyle; | ||
|
|
||
| /** Whether the modal should go under the system statusbar */ | ||
| statusBarTranslucent?: boolean; | ||
|
|
||
| /** Whether the modal should avoid the keyboard */ | ||
| avoidKeyboard?: boolean; | ||
|
|
||
| /** Modal container styles */ | ||
| innerContainerStyle?: ViewStyle; | ||
|
|
||
| /** | ||
| * Whether the modal should hide its content while animating. On iOS, set to true | ||
| * if `useNativeDriver` is also true, to avoid flashes in the UI. | ||
| * | ||
| * See: https://github.com/react-native-modal/react-native-modal/pull/116 | ||
| * */ | ||
| hideModalContentWhileAnimating?: boolean; | ||
| }; | ||
|
|
||
| export default BaseModalProps; |
Uh oh!
There was an error while loading. Please reload this page.