Home > OS >  How to make my Bottom Bar fixed in React Native?
How to make my Bottom Bar fixed in React Native?

Time:11-21

Hey

I have my bottom bar out the Scroll View component,But it still scroll with the other components. How can i make it fixed ?

"

<SafeAreaView styles={SafeViewAndroid.AndroidSafeArea}>
<View style={{ backgroundColor: "#fff", padding: 15 }}>
<HeaderTabs activeTab={activeTab} setActiveTab={setActiveTab} />
<SearchBar cityHandler={setCity} />
</View>
<ScrollView showsVerticalScrollIndicator={false}>
<Categories />
<RestaurantItems restaurantData={restaurantData} />
</ScrollView>
<Divider width={1} />
<BottomTabs />
</SafeAreaView>

"

Entire Code Screen

CodePudding user response:

You can use flex proportions to separate the and components, as below

<SafeAreaView styles={SafeViewAndroid.AndroidSafeArea}>
   <View style={{ backgroundColor: "#fff", padding: 15, flex : 1 }}>
     <HeaderTabs activeTab={activeTab} setActiveTab={setActiveTab} />
     <SearchBar cityHandler={setCity} />
  </View>
  <View style= {{flex : 3 }}>
    <ScrollView showsVerticalScrollIndicator={false}>
      <Categories />
      <RestaurantItems restaurantData={restaurantData} />
    </ScrollView>
  </View>
  <View style= {{flex : 1 }}>
    <Divider width={1} />
    <BottomTabs />
  </View>
</SafeAreaView>

CodePudding user response:

You can do it by styling your button component as -

<TouchableOpacity
    style={{
        width: 60,
        height: 60,
        backgroundColor: 'red',
        position: 'absolute',
        bottom: 50,
        justifyContent: 'center',
        alignItems: 'center',
    }}
    onPress={() => {
        console.log('Button Pressed')
    }}
>
    <Text>Hello Bottom Button</Text>
</TouchableOpacity>
  • Related