Skip to content

Commit

Permalink
feat: passes prevFrame to LoadingScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
agustif committed Sep 11, 2024
1 parent 7a32212 commit 127928c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
15 changes: 5 additions & 10 deletions packages/render/src/ui/frame.base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
FrameUIState,
RootContainerDimensions,
RootContainerElement,
PartialFrame,
} from "./types";
import {
getErrorMessageFromFramesStackItem,
Expand Down Expand Up @@ -79,8 +80,7 @@ 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 previousFrameRef = useRef<Frame |PartialFrame | null>(null);

const onImageLoadEnd = useCallback(() => {
setIsImageLoading(false);
Expand Down Expand Up @@ -244,11 +244,7 @@ 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,
},
previousFrame: previousFrameRef.current,
dimensions: rootDimensionsRef.current ?? null,
},
theme?.LoadingScreen || ({} as TStylingProps)
Expand Down Expand Up @@ -279,9 +275,8 @@ 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;
// track frame
previousFrameRef.current = frameUiState.frame;
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
6 changes: 1 addition & 5 deletions packages/render/src/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ export type FrameImageContainerProps = {

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

export type FrameButtonContainerProps = {
Expand Down

0 comments on commit 127928c

Please sign in to comment.