Skip to content

Commit

Permalink
⭐️ Impl: ModalSheetView.getCachedModalMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Sep 27, 2024
1 parent 4cbfe5f commit 2a8070f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/ModalSheetView/ModalSheetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export const ModalSheetView = React.forwardRef<
...commandArgs,
});
},
getCachedModalMetrics: () => {
return nativeRef.current?.getCachedModalMetrics();
},
getModalMetrics: async () => {
if(nativeRef.current == null) {
throw Error("Unable to get ref to native sheet");
Expand Down
1 change: 1 addition & 0 deletions src/components/ModalSheetView/ModalSheetViewTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { RNIModalSheetViewProps, RNIModalSheetViewRef } from "../../native_


type ModalSheetViewRefInherited = Pick<RNIModalSheetViewRef,
| 'getCachedModalMetrics'
| 'getModalMetrics'
>;

Expand Down
9 changes: 9 additions & 0 deletions src/native_components/RNIModalSheetVIew/RNIModalSheetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export const RNIModalSheetView = React.forwardRef<
>((props, ref) => {
const [viewID, setViewID] = React.useState<StateViewID>();
const [reactTag, setReactTag] = React.useState<StateReactTag>();

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

React.useImperativeHandle(ref, () => ({
getReactTag: () => {
Expand Down Expand Up @@ -41,6 +46,9 @@ export const RNIModalSheetView = React.forwardRef<
/* commandArgs: */ commandArgs,
);
},
getCachedModalMetrics: () => {
return cachedModalMetrics;
},
getModalMetrics: async () => {
if(viewID == null) return;
const module = Helpers.getRNIUtilitiesModule();
Expand All @@ -51,6 +59,7 @@ export const RNIModalSheetView = React.forwardRef<
/* commandArgs: */ {},
);

setCachedModalMetrics(result as any);
return result as any;
},
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type RNIModalSheetViewRef = {
isAnimated: boolean;
}) => Promise<void>;

getCachedModalMetrics: () => ModalMetrics | undefined;
getModalMetrics: () => Promise<ModalMetrics>;
};

Expand Down

0 comments on commit 2a8070f

Please sign in to comment.