Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a 'fixed header' or 'sticky header' for react native?

Is there a way to have fixed and permeant top-titlebar(I think it's called as Header?) for react native?

Almost like a status bar, it's always there. But it needs to be at the top (even before the 'header' from the react-navigation)

My plan was to put a global-search input there, so anywhere in the app you can search(Search content not affected by the screen that's presented at the moment. Pure global search always available.)

Is there a way to do this? I'm currently working with expo and react-navigation.

--- Edit

I add the screenshot of wireframe that shows what I meant. You'll notice that the Search bar stays at the top regardless the screen you are on. It's a global search bar.

-- Edit

I think I need to say this clearly. I'm trying to do this with ReactNavigation. I think I need to play with 'createAppContainer', or any create navigator function like 'createDrawerNavigator' and figure out a way to put in the fixed header with the navigate-able screens.

Example Navigation with Searchbar

like image 807
Andre Song Avatar asked Mar 20 '19 15:03

Andre Song


People also ask

How do you make a sticky header in react?

Building the StickyHeader hook isSticky && setIsSticky(true); } else { isSticky && setIsSticky(false); } }, [isSticky] ); useEffect(() => { const handleScroll = () => { toggleSticky(tableRef. current. getBoundingClientRect()); }; window. addEventListener("scroll", handleScroll); return () => { window.

Should header be sticky?

A final aspect to consider is whether the sticky header truly needed. Ultimately, by using a sticky header you give away some screen real estate on every single page of your site. And, if the sticky header is not helpful to your users, any other optimizations you make to its design are moot.


Video Answer


1 Answers

The react native's component FlastList has a property ListHeaderComponent for rendering a header and another one to stick it stickyHeaderIndices. This is exactly what you need.

In the ListHeaderComponent you will render your search field and with stickyHeaderIndices={[0]} will set it as a sticky header:

<FlatList
    data={ this.state.data }
    renderItem={({item}) =>  this.renderItem(item)}
    ListHeaderComponent={this.renderHeader}
    stickyHeaderIndices={[0]}
/>

Check out the working example.

like image 115
Hristo Eftimov Avatar answered Oct 23 '22 04:10

Hristo Eftimov