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

Search bar not rendering on iOS or Android on initial render #11627

Closed
4 of 11 tasks
homit-dalia opened this issue Oct 6, 2023 · 50 comments
Closed
4 of 11 tasks

Search bar not rendering on iOS or Android on initial render #11627

homit-dalia opened this issue Oct 6, 2023 · 50 comments

Comments

@homit-dalia
Copy link

homit-dalia commented Oct 6, 2023

Current behavior

In the initial render of the search bar through headerSearchBarOptions, it will not render. I have 4 bottom tabs and each has its own stack navigator. Search Icon does not render on initial load but would load after I switch to another tab and then current tab.

Expected behavior

The search icon should render on the first render of the screen

Reproduction

#10848

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS

Packages

  • @react-navigation/bottom-tabs
  • @react-navigation/drawer
  • @react-navigation/material-top-tabs
  • @react-navigation/stack
  • @react-navigation/native-stack
  • react-native-tab-view

Environment

  • [] I've removed the packages that I don't use
package version
@react-navigation/native
@react-navigation/bottom-tabs
@react-navigation/drawer
@react-navigation/material-top-tabs
@react-navigation/stack
@react-navigation/native-stack
react-native-safe-area-context
react-native-screens
react-native-gesture-handler
react-native-reanimated
react-native-tab-view
react-native-pager-view
react-native
node
npm or yarn
@github-actions
Copy link

github-actions bot commented Oct 6, 2023

Hey @homit-dalia! Thanks for opening the issue. It seems that the issue doesn't contain a link to a repro.

The best way to get attention to your issue is to provide an easy way for a developer to reproduce the issue.

You can provide a repro using any of the following:

A snack link is preferred since it's the easiest way to both create and share a repro. If it's not possible to create a repro using a snack, link to a GitHub repo under your username is a good alternative. Don't link to a branch or specific file etc. as it won't be detected.

Try to keep the repro as small as possible by narrowing down the minimal amount of code needed to reproduce the issue. Don't link to your entire project or a project containing code unrelated to the issue. See "How to create a Minimal, Reproducible Example" for more information.

You can edit your original issue to include a link to the repro, or leave it as a comment. The issue will be closed automatically after a while if you don't provide a repro.

@github-actions
Copy link

github-actions bot commented Oct 6, 2023

Couldn't find version numbers for the following packages in the issue:

  • @react-navigation/native
  • @react-navigation/bottom-tabs
  • @react-navigation/drawer
  • @react-navigation/material-top-tabs
  • @react-navigation/stack
  • react-native-tab-view

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

@Acetyld
Copy link

Acetyld commented Oct 13, 2023

Any update on this?

@homit-dalia
Copy link
Author

homit-dalia commented Oct 14, 2023

@Acetyld I initially set headerSearchBarOptions to true as the documentation stated that you should render atleast the UI elements in stack screens if you will update it on screen mount through .setOptions in useEffect (functional components). That was the problem. I removed headerSearchBarOptions in stack screen entirely and and now declaring it directly through .setOptions. I don't know if this is expected or headerSearchBarOptions : true is for a different context.

@github-actions
Copy link

Couldn't find version numbers for the following packages in the issue:

  • @react-navigation/native
  • @react-navigation/bottom-tabs
  • react-native-tab-view
  • @react-navigation/drawer
  • @react-navigation/material-top-tabs
  • @react-navigation/stack

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

@Robert27
Copy link

Robert27 commented Nov 8, 2023

Any updates or workarounds? :/
Using setOptions does not work on Android. iOS works fine without any hacks.

@homit-dalia
Copy link
Author

Any update on this?

I’m sorry @Robert27, but it fixed it for me after I removed headerSearchBarOptions: true in declaration and rebuilt the app.

However, it could also be an issue with if you are rendering other icons in headerRight. Try playing around the placement of those icons and see if it works.

@JcbPrn
Copy link

JcbPrn commented Nov 15, 2023

Still not working for me with the latest versions. What about you guys?

@nandorojo
Copy link
Contributor

nandorojo commented Nov 16, 2023

Hey guys, I think I fixed it by setting hideWhenScrolling: false:

  const navigation = useNavigation<Screen>()
  useLayoutEffect(() => {
    navigation.setOptions({
      headerSearchBarOptions: {
        placeholder: 'Search...',
        onCancelButtonPress: actions.stopSearching,
        onFocus: actions.startSearching,
        onChangeText: (e) => actions.onChangeText(e.nativeEvent.text),
        hideWhenScrolling: false,
      },
    })
  }, [actions, navigation])

Let me know if this fixes it for you.

Be sure to also have your scrollable component as the root node of your screen (not wrapped in a View), and to set contentInsetAdjustmentBehavior='automatic'. It also broke if I used refreshControl.

@vbornand
Copy link

@nandorojo I have still the issue on Android, but works on ios.

@WhidRubeld
Copy link

I have this problem on Android only. Adding the hideWhenScrolling: false property does not solve the problem

    "@react-navigation/native": "^6.0.8",
    "@react-navigation/native-stack": "^6.2.5",
    "@react-navigation/stack": "^6.0.11",

Copy link

Hello 👋, this issue has been open for more than a month without a repro or any activity. If the issue is still present in the latest version, please provide a repro or leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution or workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix it.

@github-actions github-actions bot added the stale label Dec 18, 2023
@ysnbyzli
Copy link

I have this problem on Android only. Adding the hideWhenScrolling: false property does not solve the problem

    "@react-navigation/native": "^6.0.8",
    "@react-navigation/native-stack": "^6.2.5",
    "@react-navigation/stack": "^6.0.11",

Hi, I have the same problem. Did you solve the problem? 🙏🏻

@WhidRubeld
Copy link

I have this problem on Android only. Adding the hideWhenScrolling: false property does not solve the problem

    "@react-navigation/native": "^6.0.8",
    "@react-navigation/native-stack": "^6.2.5",
    "@react-navigation/stack": "^6.0.11",

Hi, I have the same problem. Did you solve the problem? 🙏🏻

No, I haven't found a way around this problem. So I temporarily worked around a search modal for Android...

@vbornand
Copy link

With expo-router 3.4.1 using:
@react-navigation/native: 6.1.9
@react-navigation/native-stack: 6.9.17

The issue is resolved

@github-actions github-actions bot removed the stale label Dec 23, 2023
@sidorchukandrew
Copy link

It turns out there was an issue with react-native-screens here. Updating to 3.26.0 fixed it for me.

@ysnbyzli
Copy link

It turns out there was an issue with react-native-screens here. Updating to 3.26.0 fixed it for me.

@sidorchukandrew Hi 👋🏻, I using react-native-navigation on my expo project. When use headerSearchBarOptions not showing search icon on screen header. As you said, when I change the react-native-screens version to 3.26.0, the application stays in the splash screen, which means it crashes. So I'm using the latest version but again the search function still doesn't work.

Thank you for your interest 🙏🏻

"dependencies": {
    "@expo/vector-icons": "^13.0.0",
    "@react-native-async-storage/async-storage": "1.18.2",
    "@react-navigation/native": "^6.1.9",
    "@react-navigation/native-stack": "^6.9.17",
    "@reduxjs/toolkit": "^2.0.1",
    "@shopify/flash-list": "1.4.3",
    "expo": "~49.0.15",
    "expo-font": "~11.4.0",
    "expo-splash-screen": "~0.20.5",
    "expo-sqlite": "~11.3.3",
    "expo-status-bar": "~1.6.0",
    "react": "18.2.0",
    "react-native": "0.72.6",
    "react-native-gesture-handler": "~2.12.0",
    "react-native-reanimated": "~3.3.0",
    "react-native-safe-area-context": "4.6.3",
    "react-native-screens": "^3.29.0",
    "react-redux": "^9.0.4"
  }
useLayoutEffect(() => {
    navigation.setOptions({
      headerLargeTitle: true,
      headerSearchBarOptions: {
        inputType: "text",
        cancelButtonText: "İptal",
        tintColor: colors.primary,
        placeholder: "Ürün ara",
        onChangeText: (event) => {
          setSearch(event.nativeEvent.text);
        },
        onFocus: () => {
          setIsSearchFocused(true);
        },
        onBlur: () => {
          setIsSearchFocused(false);
        },
        hideWhenScrolling: false
      }
    });
  }, [navigation, colors]);

@Robert27
Copy link

With expo-router 3.4.1 using: @react-navigation/native: 6.1.9 @react-navigation/native-stack: 6.9.17

The issue is resolved

For me it’s not, I have the same versions. While Android is fixed, it started to appear on iOS. Now search bar is not rendered on initial render somehow.

@WhidRubeld
Copy link

With expo-router 3.4.1 using: @react-navigation/native: 6.1.9 @react-navigation/native-stack: 6.9.17

The issue is resolved

I doubt this is true. Because the problem lies in the native layer. Expo system relies on stable versions of libraries (mainly major outputs) from version to version of Expo SDK. Therefore, I think that it is worth waiting for the update along with the Expo SDK update to version 50. There will most likely already be support for React Navigation 7.

For now, I see as an alternative option to write a plugin for Expo, which will improve the work of the package.

@vbornand
Copy link

Therefore, I think that it is worth waiting for the update along with the Expo SDK update to version 50

It is resolved with Expo 50 still in preview but should be released in a couple of weeks. As mentioned above the bug is in another library.

@Robert27
Copy link

Robert27 commented Dec 26, 2023

No it’s definitely not resolved in expo sdk 50 using the latest versions of the libs.
We have a stack view with searchbar inside my tab bar and it is not rendering on the initial render on iOS. Without being nested in a tab bar it works fine.
But I agree with you that the bug is in another library.

@WhidRubeld
Copy link

Therefore, I think that it is worth waiting for the update along with the Expo SDK update to version 50

It is resolved with Expo 50 still in preview but should be released in a couple of weeks. As mentioned above the bug is in another library.

Is there a link to MR in react-native-screens to make sure that Expo 50 will merge the solution to the problem?

Copy link

github-actions bot commented Mar 7, 2024

Hello 👋, this issue has been open for more than a month without a repro or any activity. If the issue is still present in the latest version, please provide a repro or leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution or workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix it.

@github-actions github-actions bot added the stale label Mar 7, 2024
@Acetyld
Copy link

Acetyld commented Mar 7, 2024

Lets keep it open, still present

@github-actions github-actions bot removed the stale label Mar 8, 2024
@Faliszek
Copy link

Faliszek commented Mar 13, 2024

Not sure if this helps to debug, but maybe someone find useful as workaround.

For me issue fixes itself if I remove refreshing and onRefresh prop from my FlatList.
My code looks more or less like this

  useLayoutEffect(() => {
    props.navigation.setOptions({
      headerSearchBarOptions: {
        hideWhenScrolling: false,
        inputType: "text",
        placeholder: "Search assets",
        onChangeText: (event) => {
          setSearchParams((params) => ({
            ...params,
            search: event.nativeEvent.text,
          }));
        },
      },
    });
  }, [props.navigation]);

Component:

 return (
    <FlatList
      // refreshing={loading}
      // onRefresh={() => loadAssets(searchParams)}
      contentInsetAdjustmentBehavior="automatic"
      data={list}
        ListFooterComponent={() => {
        if (!loading) return null;
        return (
          <View style={styles.loadingIndicator}>
            <ActivityIndicator size="large" />
          </View>
        );
      }
      // Rest of component ...
      }} 
     />

Here are my dependencies:

    "@react-navigation/native": "^6.1.15",
    "@react-navigation/native-stack": "^6.9.24",
    "expo": "~50.0.11",
    "expo-status-bar": "~1.11.1",
    "react": "18.2.0",
    "react-native": "0.73.4",
    "react-native-safe-area-context": "4.8.2",
    "react-native-screens": "~3.29.0"

Here are screen recordings 1) Without passing refreshing and onRefresh, 2) With refreshing and onRefresh
I am guessing it is something with calculating changes on layout?

https://github.com/react-navigation/react-navigation/assets/19210348/3ab9bd7a-8eaf-436e-884e-fccccbfe4545
https://github.com/react-navigation/react-navigation/assets/19210348/19c3e364-d3b7-4d6f-ad4d-9ef9709ff5a4

Let me know if there is anything I can provide to help it debug

@amitava82
Copy link

It didn't make any difference. The basic repo case in issue #10956 has no FlatList

@coofzilla
Copy link

For me, if I remove FlatList then the search bar will render initially; however, if I add the FlatList I have to scroll first for it to appear.

@Jbraneke
Copy link

PLEASE FIX THIS PROBLEM!!!!!!!!! I NEEED HELP

@marijang
Copy link

marijang commented Apr 24, 2024

Yep, i m also trying to show and hide search bar but it is so buggy. When state change it says that i need to use useLayoutEffect....

can u add function for show/hide

useLayoutEffect(() => {
    if(events.planner.events.length > 0) {
      navigation.setOptions({
        headerSearchBarOptions: {
          placeholder: 'Search...',
          hideWhenScrolling: false,
          tintColor: theme.colors.primary,
          textColor: theme.colors.text,
          hintTextColor: theme.colors.textLight,
          
          onSearchButtonPress: ({ nativeEvent }) => {
            console.log('Search submitted:', nativeEvent.text); // Handle search submission
          },
          onChangeText: (e) => setSearchQuery(e.nativeEvent.text),
        },
      });
    }
  }, [navigation, events.planner.events.length]);

`

  

@jmarsh24
Copy link

I'm also running into this issue. Are there any temporary workarounds? This issue has been open for a long while.

@marijang
Copy link

hm im thinking to set different route if there is records or not...

Copy link

Hello 👋, this issue has been open for more than a month without a repro or any activity. If the issue is still present in the latest version, please provide a repro or leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution or workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix it.

@alberalgo
Copy link

alberalgo commented Jul 2, 2024

Using hideWhenScrolling in screenOptions of a Stack.Navigator in iOS reproduce this wrong behaviour also for me.
With any List component as root -> broken.
With any other component like a View -> correct
Any thoughts?

Copy link

github-actions bot commented Jul 2, 2024

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

@jvegax
Copy link

jvegax commented Jul 23, 2024

Still facing same issue, on Android is not working

Copy link

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

@kerimovok
Copy link

Yep, i m also trying to show and hide search bar but it is so buggy. When state change it says that i need to use useLayoutEffect....

can u add function for show/hide

useLayoutEffect(() => {
    if(events.planner.events.length > 0) {
      navigation.setOptions({
        headerSearchBarOptions: {
          placeholder: 'Search...',
          hideWhenScrolling: false,
          tintColor: theme.colors.primary,
          textColor: theme.colors.text,
          hintTextColor: theme.colors.textLight,
          
          onSearchButtonPress: ({ nativeEvent }) => {
            console.log('Search submitted:', nativeEvent.text); // Handle search submission
          },
          onChangeText: (e) => setSearchQuery(e.nativeEvent.text),
        },
      });
    }
  }, [navigation, events.planner.events.length]);

`

  

This helped, just using setOptions instead of <Stack.Screen options={...}/>

Copy link

github-actions bot commented Aug 1, 2024

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

@fredrikburmester
Copy link

I also still want a solution.

Copy link

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

1 similar comment
Copy link

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

@vladcos
Copy link

vladcos commented Nov 12, 2024

Experiencing it on Expo 51, had to set hideWhenScrolling: false as a workaround

Edit: Disregard that, not helping either

Copy link

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

@ipoogleduck
Copy link

I am still having this issue, only on android, with react native v0.74.5

Copy link

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

@ipoogleduck
Copy link

Fixed the issue I was having on Android by using the isFocused hook const isFocused = useIsFocused(), and then only setting the headerSearchBarOptions when isFocused is true. Example:

React.useLayoutEffect(() => {
        if (isFocused) { // User must be on this tab when search icon is set, or else it won't show
            navigation.setOptions({
                headerSearchBarOptions: {
                    ...
                },
            })
        }
    }, [isFocused, navigation]);

Seems like the issue was due to me having multiple bottom tabs with search bars and lazy loading turned off. The headerSearchBarOptions would try to set when the screen was not actually visible, but would fail.

Copy link

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests