Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search input to mobile search page(with fixed performance) #56326

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/node_modules/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp b/node_modules/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp
index 673ebd1..08d65fe 100644
--- a/node_modules/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp
+++ b/node_modules/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp
@@ -710,6 +710,15 @@ void NativeReanimatedModule::performOperations() {
jsPropsUpdater.call(rt, viewTag, nonAnimatableProps);
}

+ if (propsRegistry_->shouldReanimatedSkipCommit()) {
+ // It may happen that `performOperations` is called on the UI thread
+ // while React Native tries to commit a new tree on the JS thread.
+ // In this case, we should skip the commit here and let React Native do
+ // it. The commit will include the current values from PropsRegistry which
+ // will be applied in ReanimatedCommitHook.
+ return;
+ }
+
bool hasLayoutUpdates = false;
for (const auto &[shadowNode, props] : copiedOperationsQueue) {
if (isThereAnyLayoutProp(rt, props->asObject(rt))) {
45 changes: 32 additions & 13 deletions src/components/Search/SearchAutocompleteInput.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable rulesdir/no-acc-spread-in-reduce */
import type {ForwardedRef, ReactNode, RefObject} from 'react';
import React, {forwardRef, useCallback, useEffect, useLayoutEffect, useMemo, useState} from 'react';
import React, {forwardRef, useCallback, useEffect, useLayoutEffect, useMemo} from 'react';
import {View} from 'react-native';
import type {StyleProp, TextInputProps, ViewStyle} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import {useSharedValue} from 'react-native-reanimated';
import Animated, {LinearTransition, useAnimatedStyle, useSharedValue} from 'react-native-reanimated';
import FormHelpMessage from '@components/FormHelpMessage';
import type {SelectionListHandle} from '@components/SelectionList/types';
import TextInput from '@components/TextInput';
Expand All @@ -12,6 +13,7 @@ import useActiveWorkspace from '@hooks/useActiveWorkspace';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {parseFSAttributes} from '@libs/Fullstory';
import runOnLiveMarkdownRuntime from '@libs/runOnLiveMarkdownRuntime';
Expand Down Expand Up @@ -52,10 +54,10 @@ type SearchAutocompleteInputProps = {
onBlur?: () => void;

/** Any additional styles to apply */
wrapperStyle?: StyleProp<ViewStyle>;
wrapperStyle?: ViewStyle;

/** Any additional styles to apply when input is focused */
wrapperFocusedStyle?: StyleProp<ViewStyle>;
wrapperFocusedStyle?: ViewStyle;

/** Any additional styles to apply to text input along with FormHelperMessage */
outerWrapperStyle?: StyleProp<ViewStyle>;
Expand Down Expand Up @@ -84,7 +86,7 @@ function SearchAutocompleteInput(
onBlur,
caretHidden = false,
wrapperStyle,
wrapperFocusedStyle,
wrapperFocusedStyle = {},
outerWrapperStyle,
rightComponent,
isSearchingForReports,
Expand All @@ -94,8 +96,8 @@ function SearchAutocompleteInput(
ref: ForwardedRef<BaseTextInputRef>,
) {
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();
const [isFocused, setIsFocused] = useState<boolean>(false);
const {isOffline} = useNetwork();
const {activeWorkspaceID} = useActiveWorkspace();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
Expand All @@ -122,6 +124,12 @@ function SearchAutocompleteInput(

const offlineMessage: string = isOffline && shouldShowOfflineMessage ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : '';

// we are handling focused/unfocused style using shared value instead of using state to avoid re-rendering. Otherwise layout animation in `Animated.View` will lag.
const focusedSharedValue = useSharedValue(false);
const wrapperAnimatedStyle = useAnimatedStyle(() => {
return focusedSharedValue.get() ? wrapperFocusedStyle : wrapperStyle ?? {};
});

useEffect(() => {
runOnLiveMarkdownRuntime(() => {
'worklet';
Expand Down Expand Up @@ -170,7 +178,10 @@ function SearchAutocompleteInput(

return (
<View style={[outerWrapperStyle]}>
<View style={[styles.flexRow, styles.alignItemsCenter, wrapperStyle ?? styles.searchRouterTextInputContainer, isFocused && wrapperFocusedStyle]}>
<Animated.View
style={[styles.flexRow, styles.alignItemsCenter, wrapperStyle ?? styles.searchRouterTextInputContainer, wrapperAnimatedStyle]}
layout={LinearTransition}
>
<View
style={styles.flex1}
fsClass={CONST.FULL_STORY.UNMASK}
Expand All @@ -195,16 +206,17 @@ function SearchAutocompleteInput(
maxLength={CONST.SEARCH_QUERY_LIMIT}
onSubmitEditing={onSubmit}
shouldUseDisabledStyles={false}
textInputContainerStyles={[styles.borderNone, styles.pb0, styles.pr3]}
inputStyle={[inputWidth, styles.pl3, styles.pr3]}
textInputContainerStyles={[styles.borderNone, styles.pb0]}
inputStyle={[inputWidth, styles.pl3, {lineHeight: undefined}]}
placeholderTextColor={theme.textSupporting}
onFocus={() => {
setIsFocused(true);
autocompleteListRef?.current?.updateExternalTextInputFocus(true);
focusedSharedValue.set(true);
onFocus?.();
}}
onBlur={() => {
setIsFocused(false);
autocompleteListRef?.current?.updateExternalTextInputFocus(false);
focusedSharedValue.set(false);
onBlur?.();
}}
isLoading={!!isSearchingForReports}
Expand All @@ -216,8 +228,15 @@ function SearchAutocompleteInput(
selection={selection}
/>
</View>
{!!rightComponent && <View style={styles.pr3}>{rightComponent}</View>}
</View>
{!!rightComponent && (
<Animated.View
style={styles.pr3}
layout={LinearTransition}
>
{rightComponent}
</Animated.View>
)}
</Animated.View>
<FormHelpMessage
style={styles.ph3}
isError={false}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Search/SearchAutocompleteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ function SearchAutocompleteList(
const statusAutocompleteList = Object.values({...CONST.SEARCH.STATUS.TRIP, ...CONST.SEARCH.STATUS.INVOICE, ...CONST.SEARCH.STATUS.CHAT, ...CONST.SEARCH.STATUS.TRIP});
const expenseTypes = Object.values(CONST.SEARCH.TRANSACTION_TYPE);

const [userCardList = {}] = useOnyx(ONYXKEYS.CARD_LIST);
const [workspaceCardFeeds = {}] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST);
const allCards = useMemo(() => mergeCardListWithWorkspaceFeeds(workspaceCardFeeds, userCardList), [userCardList, workspaceCardFeeds]);
const [userCardList] = useOnyx(ONYXKEYS.CARD_LIST);
const [workspaceCardFeeds] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST);
const allCards = useMemo(() => mergeCardListWithWorkspaceFeeds(workspaceCardFeeds ?? CONST.EMPTY_OBJECT, userCardList), [userCardList, workspaceCardFeeds]);
const cardAutocompleteList = Object.values(allCards);

const participantsAutocompleteList = useMemo(() => {
Expand Down
Loading
Loading