Skip to content

Commit

Permalink
⭐️ Impl: ModalViewState.focusState
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Apr 22, 2023
1 parent e9efa35 commit 4d63a30
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/ModalView/ModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class ModalView extends
enableSwipeGesture: defaultProps.enableSwipeGesture,
isModalInPresentation: defaultProps.isModalInPresentation,
isModalInFocus: false,
focusState: 'INITIAL',
};
}

Expand Down Expand Up @@ -483,6 +484,10 @@ export class ModalView extends
ModalViewEmitterEvents.onModalWillFocus,
event.nativeEvent
);

this.setState({
focusState: event.nativeEvent.modalFocusState,
});
};

private _handleOnModalDidFocus: OnModalDidFocusEvent = (event) => {
Expand All @@ -509,6 +514,7 @@ export class ModalView extends

this.setState({
isModalInFocus: true,
focusState: event.nativeEvent.modalFocusState,
});
};

Expand All @@ -522,6 +528,10 @@ export class ModalView extends
ModalViewEmitterEvents.onModalWillBlur,
event.nativeEvent
);

this.setState({
focusState: event.nativeEvent.modalFocusState,
});
};

private _handleOnModalDidBlur: OnModalDidBlurEvent = (event) => {
Expand All @@ -548,6 +558,7 @@ export class ModalView extends

this.setState({
isModalInFocus: false,
focusState: event.nativeEvent.modalFocusState,
});
};

Expand Down Expand Up @@ -620,7 +631,7 @@ export class ModalView extends
);
};

private _handleOnModalDetentDidCompute:
private _handleOnModalDetentDidCompute:
OnModalDetentDidComputeEvent = (event) => {

const props = this.props;
Expand Down Expand Up @@ -736,6 +747,7 @@ export class ModalView extends
value={{
isModalInFocus: state.isModalInFocus,
isModalVisible: state.isModalVisible,
focusState: state.focusState,

// pass down function to get modal refs
getModalRef: this._handleGetModalRef,
Expand Down
4 changes: 4 additions & 0 deletions src/components/ModalView/ModalViewState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { RNIModalFocusState } from 'src/types/RNIModalTypes';

export type ModalViewState = {
isModalVisible: boolean;
childProps: unknown;
enableSwipeGesture: boolean;
isModalInPresentation: boolean;
isModalInFocus: boolean;

focusState: RNIModalFocusState;
};
1 change: 1 addition & 0 deletions src/components/ModalView/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './ModalView';
export * from './ModalViewProps';
export * from './ModalViewState';
export * from './ModalViewEmitter';
export * from './ModalViewEmitterDeprecated';
1 change: 1 addition & 0 deletions src/context/ModalContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type ModalContextType = Partial<
ModalViewState,
| 'isModalInFocus'
| 'isModalVisible'
| 'focusState'
>
// `ModalView` Methods #2
& {
Expand Down
7 changes: 7 additions & 0 deletions src/types/RNIModalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ export type RNIModalCustomSheetDetent = {
key: string;
sizeConstant: number;
};

export type RNIModalFocusState =
| 'INITIAL'
| 'FOCUSING'
| 'FOCUSED'
| 'BLURRING'
| 'BLURRED';

0 comments on commit 4d63a30

Please sign in to comment.