You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, currently I am trying to achieve a sliding bottom component in RN 0.76 using RNA 3.16. The component is working fine in RN 0.74 but not in latest native version.
In RN 0.76, the component's height is not changing on initial render but when I change tab, it is working as expected.
BottomTabNavigator.js file: This file contains BottomTabNavigator as well as SlidingBottom.js component
constBottomTab=createBottomTabNavigator();const{ height }=Dimensions.get('window');constSNAP_TOP=height+StatusBar.currentHeight;constSNAP_BOTTOM=54+50;constBottomTabNavigator=()=>{constyValue=useSharedValue(SNAP_BOTTOM);return(<>{/* this component contain all screen and bottom tab navigator */}<BottomTab.NavigatortabBar={(props)=><BottomTabBar{...props}yValue={yValue}snapTop={SNAP_TOP}snapBottom={SNAP_BOTTOM}/>}initialRouteName="Home"// "Home" initial screen to render backBehavior="history"screenOptions={{headerShown: false,tabBarHideOnKeyboard: true,}}><BottomTab.Screenname="Home"component={Home}options={{tabBarLabel: "Home",// we are importing focused as well as size from BottomTabBar.js filetabBarIcon: ({ color })=><HomeIconheight={icon_size}width={icon_size}fill={color}/>,}}/><BottomTab.Screenname="Search"component={Search}options={{tabBarLabel: "Search",tabBarIcon: ({ color })=><SearchIconheight={icon_size}width={icon_size}fill={color}/>}}/></BottomTab.Navigator>{/* this component contains the mini player & player page */}<SlidingBottomyValue={yValue}snapTop={SNAP_TOP}snapBottom={SNAP_BOTTOM}/></>);}exportdefaultBottomTabNavigator;
SlidingBottom.js: This contains the component that is facing issue
import{useEffect,useState,useMemo}from"react";import{Dimensions,Keyboard,Text,View,TouchableOpacity,StatusBar,StyleSheet}from"react-native";import{useTheme}from"@react-navigation/native";importAnimated,{Extrapolation,interpolate,useSharedValue,useAnimatedStyle,withTiming,Easing}from"react-native-reanimated";// import constantsimport{color_schema,icon_size,layout_schema}from"../../constants/constants";const{ height }=Dimensions.get('window');constBottomTabBar=({ state, descriptors, navigation, yValue, snapTop, snapBottom })=>{// using this hook we can get all colors used by react navigation // as hooks can be only called inside function that's why we cannot declare all styles in StyleSheetconst{ colors }=useTheme();// this is used to check if keyboard is visible or notconst[keyboardVisible,setKeyboardVisible]=useState(true);useEffect(()=>{constkeyboardDidShowListener=Keyboard.addListener("keyboardDidShow",()=>{//Whenever keyboard did show make it don't visiblesetKeyboardVisible(false);});constkeyboardDidHideListener=Keyboard.addListener("keyboardDidHide",()=>{setKeyboardVisible(true);});return()=>{keyboardDidShowListener.remove();keyboardDidHideListener.remove();};},[])constbStyle=useAnimatedStyle(()=>({// height: interpolate(yValue.value, [snapTop, snapBottom], [0, 54], Extrapolation.CLAMP), then add bottom: 0 in styles.bottombottom: interpolate(yValue.value,[snapTop,snapBottom],[-54,0],Extrapolation.CLAMP)}));return(keyboardVisible&&<Animated.Viewstyle={[styles.bottom,bStyle,{backgroundColor: colors.card}]}>{state.routes.map((route,index)=>{const{ options }=descriptors[route.key];constlabel=options.tabBarLabel!==undefined
? options.tabBarLabel
: options.title!==undefined
? options.title
: route.name;constisFocused=useMemo(()=>state.index===index,[state.index]);{/* function for onPress event */}constonPress=()=>{constevent=navigation.emit({type: "tabPress",target: route.key,});if(!isFocused&&!event.defaultPrevented){navigation.navigate(route.name);}};{/* function for onLongPress event */}constonLongPress=()=>{constevent=navigation.emit({type: "tabLongPress",target: route.key,});if(!isFocused&&!event.defaultPrevented){navigation.navigate(route.name);}};{/* setting color for icon and text */}constcolor=isFocused ? color_schema.focused_header_color : color_schema.unfocused_header_colorconstwidthSharedValue=useSharedValue(isFocused ? "100%" : "0%");useEffect(()=>{widthSharedValue.value=withTiming(isFocused ? "100%" : "0%",{duration: 300,easing: Easing.bounce,})},[state.index])constanimatedWidth=useAnimatedStyle(()=>{'worklet';return{width: widthSharedValue.value,};})return(<TouchableOpacitykey={route.key}// using route.key for unique keys but we can use index also// accessibilityRole="button"accessibilityState={isFocused ? {selected: true} : {}}accessibilityLabel={options.tabBarAccessibilityLabel}testID={options.tabBarTestID}onPress={onPress}onLongPress={onLongPress}><Viewstyle={styles.navItem}>{/* this view contains icon */}<View>{options.tabBarIcon({ color,focused: isFocused,size: icon_size})}</View>{/* this view contains label */}<Viewstyle={styles.labelContainer}><Textstyle={[styles.label,{ color }]}>{label}</Text></View>{/* this view contains undedrline */}<Animated.Viewstyle={[styles.underline,animatedWidth]}/></View></TouchableOpacity>);})}</Animated.View>);}conststyles=StyleSheet.create({bottom: {borderTopColor: color_schema.border_bottom_color,borderTopWidth: 1,flexDirection: "row",justifyContent: "space-evenly",alignItems: "center",paddingTop: 5,paddingBottom: 2,position: "absolute",left: 0,right: 0,zIndex: layout_schema.zIndexForBottomTabNavigator,height: 54,overflow: "hidden",},navItem: {display: "flex",flexDirection: "column",justifyContent: "center",alignItems: "center",width: "100%",},labelContainer: {marginTop: -1,marginBottom: 1,marginHorizontal: "auto",width: "auto",},label: {fontSize: 10,fontWeight: "400",},underline: {backgroundColor: color_schema.focused_header_color,borderRadius: 2,height: 2,},});exportdefaultBottomTabBar;
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
So, currently I am trying to achieve a sliding bottom component in RN 0.76 using RNA 3.16. The component is working fine in RN 0.74 but not in latest native version.
In RN 0.76, the component's height is not changing on initial render but when I change tab, it is working as expected.
BottomTabNavigator.js file: This file contains BottomTabNavigator as well as SlidingBottom.js component
SlidingBottom.js: This contains the component that is facing issue
Also, I am using custom BottomTabBar:
Kindly help me community!!!
Beta Was this translation helpful? Give feedback.
All reactions