Skip to content

Commit

Permalink
feat: passes down info about previousFrame to LoadingScreen component…
Browse files Browse the repository at this point in the history
… like aspect ratio, buttons, and input
  • Loading branch information
agustif committed Sep 11, 2024
1 parent 303a851 commit 7a32212
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/render/src/ui/frame.base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export function BaseFrameUI<TStylingProps extends Record<string, unknown>>({
const rootRef = useRef<RootContainerElement>(null);
const rootDimensionsRef = useRef<RootContainerDimensions | undefined>();
const previousFrameAspectRatioRef = useRef<"1:1" | "1.91:1" | undefined>();
const previousFrameButtonsRef = useRef<number | null>(null);
const previousFrameTextInputRef = useRef<boolean | null>(null);

const onImageLoadEnd = useCallback(() => {
setIsImageLoading(false);
Expand Down Expand Up @@ -242,6 +244,11 @@ export function BaseFrameUI<TStylingProps extends Record<string, unknown>>({
? components.LoadingScreen(
{
frameState: frameUiState,
previousFrame: {
aspectRatio: previousFrameAspectRatioRef.current ?? null,
buttons: previousFrameButtonsRef.current ?? 0,
textInput: previousFrameTextInputRef.current ?? false,
},
dimensions: rootDimensionsRef.current ?? null,
},
theme?.LoadingScreen || ({} as TStylingProps)
Expand Down Expand Up @@ -272,6 +279,9 @@ export function BaseFrameUI<TStylingProps extends Record<string, unknown>>({
previousFrameAspectRatioRef.current =
frameUiState.frame.imageAspectRatio ?? "1.91:1";

// track number of buttons
previousFrameButtonsRef.current = frameUiState.frame.buttons?.length ?? 0;
previousFrameTextInputRef.current = frameUiState.frame.inputText !== undefined;
Promise.resolve(
frameState.onButtonPress(
// @todo change the type onButtonPress to accept partial frame as well because that can happen if partial frames are enabled
Expand Down
5 changes: 5 additions & 0 deletions packages/render/src/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export type FrameImageContainerProps = {

export type FrameLoadingScreenProps = FrameUIStateProps & {
dimensions: RootContainerDimensions | null;
previousFrame?: {
aspectRatio?: "1:1" | "1.91:1" | null;
buttons?: number;
textInput?: boolean;
};
};

export type FrameButtonContainerProps = {
Expand Down

0 comments on commit 7a32212

Please sign in to comment.