Skip to content

Commit

Permalink
💫 Update: Ex - ModalSheetViewTest01
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Sep 27, 2024
1 parent 96c073a commit d4a19aa
Showing 1 changed file with 77 additions and 3 deletions.
80 changes: 77 additions & 3 deletions example/src/examples/ModalSheetViewTest01.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import { ExampleItemCard, ObjectPropertyDisplay, CardButton, Colors } from 'reac
import { ModalSheetView, ModalSheetViewMainContent, type ModalSheetViewRef } from 'react-native-ios-modal';

import type { ExampleItemProps } from './SharedExampleTypes';
import type { ModalMetrics } from '../../../src/types/ModalMetrics';


export function ModalSheetViewTest01(props: ExampleItemProps) {
const modalSheetViewRef = React.useRef<ModalSheetViewRef | null>(null);

const [
modalMetrics,
setModalMetrics
] = React.useState<ModalMetrics | undefined>();

const [
shouldMountRecursiveContent,
setShouldMountRecursiveContent,
Expand All @@ -19,6 +25,37 @@ export function ModalSheetViewTest01(props: ExampleItemProps) {
const recursionLevel =
props.extraProps?.recursionLevel as any as number ?? 0;

let dataForDebugDisplay = {
};

if(modalMetrics != null) {
const modalMetricsUpdated = {
...modalMetrics,
modalViewControllerMetrics: {
...modalMetrics.modalViewControllerMetrics,
instanceID: [
modalMetrics.modalViewControllerMetrics.instanceID
],
},
presentationControllerMetrics: {
...modalMetrics.presentationControllerMetrics,
instanceID: [
modalMetrics.presentationControllerMetrics?.instanceID
],
},
};

dataForDebugDisplay = {
...dataForDebugDisplay,
...modalMetricsUpdated
};
};

const hasDataForDebugDisplay =
Object.keys(dataForDebugDisplay).length > 0;

const isFirstRecursion = (recursionLevel == 0);

return (
<ExampleItemCard
style={props.style}
Expand All @@ -30,7 +67,10 @@ export function ModalSheetViewTest01(props: ExampleItemProps) {
>
<ObjectPropertyDisplay
recursiveStyle={styles.debugDisplayInner}
object={undefined}
object={hasDataForDebugDisplay
? dataForDebugDisplay
: undefined
}
/>
<CardButton
title={'Present Sheet Modal'}
Expand All @@ -46,12 +86,19 @@ export function ModalSheetViewTest01(props: ExampleItemProps) {
}}
/>
<React.Fragment>
{(recursionLevel != 0) && (
{!isFirstRecursion && (
<CardButton
title={'Dismiss Modal'}
subtitle={'Dismiss current modal'}
onPress={async () => {
await modalSheetViewRef.current?.dismissModal();
const modalSheetViewRefPrev: ModalSheetViewRef | null =
props.extraProps?.modalSheetViewRefPrev as any;

if(modalSheetViewRefPrev == null){
return;
};

await modalSheetViewRefPrev.dismissModal();
console.log(
'ModalSheetViewTest01',
'\n - dismiss modal completed',
Expand All @@ -60,6 +107,32 @@ export function ModalSheetViewTest01(props: ExampleItemProps) {
}}
/>
)}
{!isFirstRecursion && (
<CardButton
title={'Get modal metrics for prev. modal'}
subtitle={'invoke `getModalMetrics`'}
onPress={async () => {

const modalSheetViewRefPrev: ModalSheetViewRef | null =
props.extraProps?.modalSheetViewRefPrev as any;

if(modalSheetViewRefPrev == null){
return;
};

const modalMetrics =
await modalSheetViewRefPrev.getModalMetrics();

setModalMetrics(modalMetrics);
console.log(
'ModalSheetViewTest01',
'\n - invoked getModalMetrics',
'\n',
modalMetrics,
);
}}
/>
)}
</React.Fragment>
<ModalSheetView
ref={ref => modalSheetViewRef.current = ref}
Expand All @@ -77,6 +150,7 @@ export function ModalSheetViewTest01(props: ExampleItemProps) {
index={props.index}
extraProps={{
recursionLevel: recursionLevel + 1,
modalSheetViewRefPrev: modalSheetViewRef.current,
}}
/>
)}
Expand Down

0 comments on commit d4a19aa

Please sign in to comment.