From 7d166cf8fdf05dbfddb1964520874192c6f0721a Mon Sep 17 00:00:00 2001 From: James Hu Date: Sun, 26 Nov 2023 05:04:27 -0800 Subject: [PATCH] Fix issue for not rendering on object property state change --- src/GiftedChat.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/GiftedChat.tsx b/src/GiftedChat.tsx index eaa351ae6..21bb47f95 100644 --- a/src/GiftedChat.tsx +++ b/src/GiftedChat.tsx @@ -220,7 +220,6 @@ export interface GiftedChatProps { } export interface GiftedChatState { - isInitialized: boolean composerHeight?: number messagesContainerHeight?: number | Animated.Value typingDisabled: boolean @@ -274,7 +273,6 @@ function GiftedChat( let _isTextInputWasFocused: boolean = false const [state, setState] = useState({ - isInitialized: false, // initialization will calculate maxHeight before rendering the chat composerHeight: minComposerHeight, messagesContainerHeight: undefined, typingDisabled: false, @@ -282,6 +280,8 @@ function GiftedChat( messages: undefined, }) + const [isInitialized,setIsInitialized] = useState(false); + useEffect(() => { isMountedRef.current = true @@ -604,11 +604,11 @@ function GiftedChat( setState({ ...state, - isInitialized: true, text: getTextFromProp(initialText), composerHeight: minComposerHeight, messagesContainerHeight: newMessagesContainerHeight, - }) + }); + setIsInitialized(true); } const onMainViewLayout = (e: LayoutChangeEvent) => { @@ -681,7 +681,7 @@ function GiftedChat( [actionSheet, locale], ) - if (state.isInitialized === true) { + if (isInitialized === true) { return (