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

Tabs crash app with error "RCTView",{"transform":[{"translateX":"<<NaN>>"}]}] is not usable as a native method argument #3784

Open
1 task done
DarylBeattie opened this issue May 5, 2023 · 31 comments · May be fixed by #3807

Comments

@DarylBeattie
Copy link

DarylBeattie commented May 5, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Explain what you did

I have an app with:

  • 2 separate sets of tabs, on different screens.
  • Each set of tabs contains only 2 tabs.
  • Animation is set to true.
  • All Tabs/TabViews take up 100% width of each screen they are in, except some of the screens the Tabs take up 90% (because there's a back "<" beside them) where the TabViews still take up 100% width.
  • I have set the widths to "100%", left the widths empty, and set the widths to useWindowDimensions().width, and it still happens.
  • React Native bottom-drawer navigation to go between screens.
  • Running on iOS, using ExpoGo.
  • I have tested with the latest RNEUI release, and the "bleeding edge" as well.

Expected behavior

I expect the app not to crash and to be able to use my Tabs normally.

Describe the bug

When I go from page to page, and tab-to-tab within those pages, the app crashes randomly with "Render Error" showing:

ERROR Invariant Violation: [109,"RCTView",{"transform":[{"translateX":"<<NaN>>"}]}] is not usable as a native method argument

There is an error with the Tab animations.
My app crashes randomly, but only after a few times switching back and forth between windows containing tabs.

Deeper Dive:

I have tried to debug this issue myself in Tab.tsx (and TabView.tsx), and have found that indeed the isNan() is returning true for values being passed into transform->translateX. Though, this could be because they are Animated.Values and not just scalar number types, so they are "not numbers". When I JSON.stringify() the translateX values, they always give me 0. However, I have read somewhere that when you try to print the value of an Animated.Value when you're using useNativeDriver: true it always returns 0; not sure how true that is.

The line of code that causes the error is here from Tab.tsx [formatted for bug report]:
transform: [ { translateX: indicatorTransitionInterpolate, }, ],

This could be happening because of the useRefs being used for animationRef.

It also could be an issue with how indicatorTransitionInterpolate is computed.

I have tried to add extrapolate: "clamp" to the interpolation, but that didn't help.
If I check for isNaN() and simply return the other value, it has the effect of removing the animation completely (value is always 0).

The full error looks like this:

ERROR  Invariant Violation: [107,"RCTView",{"transform":[{"translateX":"<<NaN>>"}]}] is not usable as a native method argument

This error is located at:
    in RCTView (created by View)
    in View (created by AnimatedComponent)
    in AnimatedComponent
    in AnimatedComponentWrapper (created by Tab)
    in RCTView (created by View)
    in View (created by Tab)
    in Tab
    in Themed.Tab (created by BrowseScreen)
    in RCTView (created by View)
    in View (created by BrowseScreen)
    in RCTView (created by View)
    in View (created by BrowseScreen)
    in BrowseScreen (created by SceneView)
    in StaticContainer
    in EnsureSingleNavigator (created by SceneView)
    in SceneView (created by SceneView)
    in RCTView (created by View)
    in View (created by DebugContainer)
    in DebugContainer (created by MaybeNestedStack)
    in MaybeNestedStack (created by SceneView)
    in RCTView (created by View)
    in View (created by SceneView)
    in RNSScreen (created by AnimatedComponent)
    in AnimatedComponent
    in AnimatedComponentWrapper (created by InnerScreen)
    in Suspender (created by Freeze)
    in Suspense (created by Freeze)
    in Freeze (created by DelayedFreeze)
    in DelayedFreeze (created by InnerScreen)
    in InnerScreen (created by Screen)
    in Screen (created by SceneView)
    in SceneView (created by NativeStackViewInner)
    in Suspender (created by Freeze)
    in Suspense (created by Freeze)
    in Freeze (created by DelayedFreeze)
    in DelayedFreeze (created by ScreenStack)
    in RNSScreenStack (created by ScreenStack)
    in ScreenStack (created by NativeStackViewInner)
    in NativeStackViewInner (created by NativeStackView)
    in RCTView (created by View)
    in View (created by SafeAreaInsetsContext)
    in SafeAreaProviderCompat (created by NativeStackView)
    in NativeStackView (created by NativeStackNavigator)
    in PreventRemoveProvider (created by NavigationContent)
    in NavigationContent
    in Unknown (created by NativeStackNavigator)
    in NativeStackNavigator (created by BrowseStackScreens)
    in BrowseStackScreens (created by SceneView)
    in StaticContainer
    in EnsureSingleNavigator (created by SceneView)
    in SceneView (created by BottomTabView)
    in RCTView (created by View)
    in View (created by Screen)
    in RCTView (created by View)
    in View (created by Background)
    in Background (created by Screen)
    in Screen (created by BottomTabView)
    in RNSScreen (created by AnimatedComponent)
    in AnimatedComponent
    in AnimatedComponentWrapper (created by InnerScreen)
    in Suspender (created by Freeze)
    in Suspense (created by Freeze)
    in Freeze (created by DelayedFreeze)
    in DelayedFreeze (created by InnerScreen)
    in InnerScreen (created by Screen)
    in Screen (created by MaybeScreen)
    in MaybeScreen (created by BottomTabView)
    in RNSScreenNavigationContainer (created by ScreenContainer)
    in ScreenContainer (created by MaybeScreenContainer)
    in MaybeScreenContainer (created by BottomTabView)
    in RCTView (created by View)
    in View (created by SafeAreaInsetsContext)
    in SafeAreaProviderCompat (created by BottomTabView)
    in BottomTabView (created by BottomTabNavigator)
    in PreventRemoveProvider (created by NavigationContent)
    in NavigationContent
    in Unknown (created by BottomTabNavigator)
    in BottomTabNavigator (created by HomeScreen)
    in EnsureSingleNavigator
    in BaseNavigationContainer
    in ThemeProvider
    in NavigationContainerInner (created by HomeScreen)
    in RCTView (created by View)
    in View (created by HomeScreen)
    in MatchesProvider (created by HomeScreen)
    in HomeScreen (created by SceneView)
    in StaticContainer
    in EnsureSingleNavigator (created by SceneView)
    in SceneView (created by SceneView)
    in RCTView (created by View)
    in View (created by DebugContainer)
    in DebugContainer (created by MaybeNestedStack)
    in MaybeNestedStack (created by SceneView)
    in RCTView (created by View)
    in View (created by SceneView)
    in RNSScreen (created by AnimatedComponent)
    in AnimatedComponent
    in AnimatedComponentWrapper (created by InnerScreen)
    in Suspender (created by Freeze)
    in Suspense (created by Freeze)
    in Freeze (created by DelayedFreeze)
    in DelayedFreeze (created by InnerScreen)
    in InnerScreen (created by Screen)
    in Screen (created by SceneView)
    in SceneView (created by NativeStackViewInner)
    in Suspender (created by Freeze)
    in Suspense (created by Freeze)
    in Freeze (created by DelayedFreeze)
    in DelayedFreeze (created by ScreenStack)
    in RNSScreenStack (created by ScreenStack)
    in ScreenStack (created by NativeStackViewInner)
    in NativeStackViewInner (created by NativeStackView)
    in RNCSafeAreaProvider (created by SafeAreaProvider)
    in SafeAreaProvider (created by SafeAreaInsetsContext)
    in SafeAreaProviderCompat (created by NativeStackView)
    in NativeStackView (created by NativeStackNavigator)
    in PreventRemoveProvider (created by NavigationContent)
    in NavigationContent
    in Unknown (created by NativeStackNavigator)
    in NativeStackNavigator (created by Navigation)
    in EnsureSingleNavigator
    in BaseNavigationContainer
    in ThemeProvider
    in NavigationContainerInner (created by Navigation)
    in RCTView (created by View)
    in View (created by Navigation)
    in RNCSafeAreaProvider (created by SafeAreaProvider)
    in SafeAreaProvider (created by App)
    in Navigation (created by App)
    in OnboardingProvider (created by App)
    in AuthUserProvider (created by App)
    in ThemeProvider (created by App)
    in Provider (created by App)
    in App (created by withDevTools(App))
    in withDevTools(App)
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in main(RootComponent), js engine: hermes

(Basically you can see from this my screen components are App > Navigation > Home > Browse, which has Tabs.)

Steps To Reproduce

Besides setting up an entire app that mimics the behavior, I'm not sure how to reproduce this error. And, I'm very sorry to say, I don't have the time to fully create a Snack to reproduce it.

Screenshots

No response

Your Environment

`npx @rneui/envinfo`
  ```

React Native Elements Env Info

Global Dependencies:

No related dependency found

Local Dependencies:

  • @rneui/base : ^0.0.0-edge.2
  • @rneui/themed : ^0.0.0-edge.2
  • expo : ~48.0.6
  • react : 18.2.0
  • react-native : 0.71.7 ```
@DarylBeattie DarylBeattie changed the title Tab/TabView crash app with error "RCTView",{"transform":[{"translateX":"<<NaN>>"}]}] is not usable as a native method argument Tabs crash app with error "RCTView",{"transform":[{"translateX":"<<NaN>>"}]}] is not usable as a native method argument May 5, 2023
@DarylBeattie
Copy link
Author

I have temporarily stopped this error from crashing my app by changing Tab's indicator's Animated.View to transform to:

transform: [
    {
        translateX: isNaN(indicatorTransitionInterpolate) ? value * (WIDTH?WIDTH:0) : indicatorTransitionInterpolate,
    },
],

However, this means the animation doesn't work, though the indicator does flip to the correct tab.
FWIW, isNaN(indicatorTransitionInterpolate) always returns true.

I believe this bug is due to having multiple Tab components on different screens, as the app crashes when I flip to a screen that has another set of Tabs.

Sometimes when I flip to another screen, the "WIDTH" variable is undefined for the first render and gets set sometime later, hence the (WIDTH?WIDTH:0) in the code above. It might be a similar issue with the ref()s not updating quickly enough to be used in the return.

@richstokes
Copy link

richstokes commented May 7, 2023

I am seeing the same thing. I am just using Tabs, not TabView, very simply with:

<View>
    <Tab
        value={index}
        onChange={(e) => setIndex(e)}
        indicatorStyle={{
            backgroundColor: isDarkMode ? 'white' : 'darkgrey',
            height: 2,
        }}
        variant="primary"
        dense
        containerStyle={{
            backgroundColor: style.backgroundColor,
            borderColor: style.backgroundColor,
            borderWidth: 0,
            height: 50,
        }}
        buttonStyle={{
            backgroundColor: style.backgroundColor,
            borderColor: style.backgroundColor,
            borderWidth: 0,
            height: 50,
        }}
    >
        <Tab.Item
            title="Tab 1"
            titleStyle={{ fontSize: 12 }}
            icon={{ name: 'document-text', type: 'ionicon' }}
        />
        <Tab.Item
            title="Tab 2"
            titleStyle={{ fontSize: 12 }}
            icon={{ name: 'arrow-redo', type: 'ionicon' }}
        />
        <Tab.Item
            title="Tab 3"
            titleStyle={{ fontSize: 12 }}
            icon={{ name: 'heart', type: 'ionicon' }}
        />
    </Tab>
</View >

The only interesting thing is these are part of a FlatList header. Wondering if thats a clue, I'm really not sure though as its very intermittent for me.

Not sure if directly related, but I also often see this error immediately after the error in the subject of this issue:

Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.

[[57,57,57,57,57,57,57,32,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,9],[2,0,2,0,2,0,2,6,10,5,4,11,3,13,3,3,13,13,11,3,3,13,13,3],[[231,255],[256,{"transforms":[{"nodeTag":255,"property":"translateX","type":"animated"}],"type":"transform"}],[255,256],[257,{"style":{"transform":256},"type":"style"}],[256,257],[258,{"props":{"style":257},"type":"props"}],[257,258],[258,7445],[62],[74,231,{"iterations":1,"toValue":0,"frames":[0,0.03114100006836614,0.1074304693764467,0.21455988464815853,0.3458169666596566,0.5,0.6541830333403433,0.7854401153518413,0.8925695306235534,0.9688589999316338,1],"type":"frames"},14935],[148,285],[147,148],[147],[146,148],[145,146],[146],[148],[150,125],[149,150],[145,149],[149],[150],[1]],7457]

This error is located at:
    in PanGestureHandler (created by PanGestureHandler)
    in PanGestureHandler (created by Card)
    in RCTView (created by View)
    in View (created by AnimatedComponent)
    in AnimatedComponent
    in AnimatedComponentWrapper (created by Card)

@DarylBeattie
Copy link
Author

@richstokes Yes, you are right; I also got those "field sizes are different" exceptions each time along with the main exception.
@richstokes Question for you: Do you have multiple sets of tabs in your application?

Also, I'd like to report that this problem is DEFINITELY in animating the tab-indicator. My work-around posted in a comment above completely avoids the error, I've never seen it since. However, it has the effect of removing the animation from the tab-indicator entirely.

I don't know how to fix this bug or I would submit a PR myself.

@richstokes
Copy link

I don't have multiple sets of tabs, per-se, but in theory the screen may be stacked on top of other screens that render the same tabs.

Can I disable the animation? I'm not sure how you did that - did you edit the RNE code to do so?

@DarylBeattie
Copy link
Author

@richstokes Yes I did disable the animation and that has SOLVED the crashing.
I did so by editing node_modules/@rneui/base-edge/dist/Tab.js
changing the transform-translateX near the bottom of the file to be (like from my second comment):

transform: [
    {
        translateX: isNaN(indicatorTransitionInterpolate) ? value * (WIDTH?WIDTH:0) : indicatorTransitionInterpolate,
    },
],

(Note I'm using "bleeding edge", yours might be slightly different.)

Since the isNaN() always seems to return true, it has the effect of flipping the indicator to the correct tab when the WIDTH changes.

@DarylBeattie
Copy link
Author

I hate to nag, but umm: Could something be done about this problem?
It is preventing me from publishing my app, which my company and clients depend on. I cannot publish an app that has tabs that completely crash the app. I would consider it a P1 issue with RNEUI.

@arpitBhalla it seems you've done much of the work on this feature, could you please take a look? I could assist with any testing you need.

@dongsuo
Copy link

dongsuo commented May 22, 2023

I'm facing the same problem on my App, looking forward to a more elegant solution.

@brownieboy
Copy link

translateX: isNaN(indicatorTransitionInterpolate) ? value * (WIDTH?WIDTH:0) : indicatorTransitionInterpolate,

Your workaround did the trick for me, @DaryBeattie.

If nobody's working on a proper fix for this, then perhaps you could submit your workaround as a PR in the meantime? It's got to be better than having our apps crashing!

@arpitBhalla
Copy link
Member

I'm working on this, will release a patch till end of this week.

@matthauber92
Copy link

Is this issue still being addressed?

@letelete
Copy link

letelete commented Jul 5, 2023

Any updates on this?

@arpitBhalla arpitBhalla linked a pull request Jul 5, 2023 that will close this issue
14 tasks
@arpitBhalla
Copy link
Member

arpitBhalla commented Jul 5, 2023

Can you try using

yarn add react-native-elements/react-native-elements#base-3807
import { Tabs, TabsRef } from "@rneui/base/dist/Tab/Tab";
import { Button, Tab as TabBar, TabView, Text } from "@rneui/base";
import React, { useRef } from "react";
import { ScrollView } from "react-native";

export default () => {
  const tabRef = useRef<TabsRef>();

  return (
    <>
      <Tabs ref={tabRef}>
        <TabBar
          titleStyle={{ fontSize: 12 }}
          indicatorStyle={{
            backgroundColor: "white",
            height: 3,
          }}
          style={{ height: 70 }}
          scrollable
        >
          <TabBar.Item
            title="Recent"
            icon={{ name: "timer", type: "ionicon", color: "white" }}
          />
          <TabBar.Item
            title="Custom"
            containerStyle={(active) => ({
              backgroundColor: active ? "#208990" : "transparent",
            })}
            icon={{ name: "heart", type: "ionicon", color: "white" }}
          />
          <TabBar.Item
            title="Cart"
            icon={{ name: "cart", type: "ionicon", color: "white" }}
          />
          <TabBar.Item
            title="Example tab 1"
            icon={{ name: "cart", type: "ionicon", color: "white" }}
          />
          <TabBar.Item
            title="Example tab 2"
            icon={{ name: "cart", type: "ionicon", color: "white" }}
          />
          <TabBar.Item
            title="Example tab 3"
            icon={{ name: "cart", type: "ionicon", color: "white" }}
          />
        </TabBar>

        <TabView onSwipeStart={console.log}>
          <TabView.Item style={{ backgroundColor: "red", width: "100%" }}>
            <ScrollView>
              <Button onPress={() => tabRef.current?.changeIndex(2)}>
                Jump to Tab 3
              </Button>
              <Text h1>{Math.random()}</Text>
            </ScrollView>
          </TabView.Item>

          <TabView.Item style={{ backgroundColor: "blue", width: "100%" }}>
            <Text h1>Favorite 1</Text>
          </TabView.Item>

          <TabView.Item style={{ backgroundColor: "green", width: "100%" }}>
            <Text h1>Cart 2${Math.random()}</Text>
          </TabView.Item>

          <TabView.Item style={{ backgroundColor: "red", width: "100%" }}>
            <Text h1>Example 3</Text>
          </TabView.Item>

          <TabView.Item style={{ backgroundColor: "blue", width: "100%" }}>
            <Text h1>Example 4</Text>
          </TabView.Item>

          <TabView.Item style={{ backgroundColor: "green", width: "100%" }}>
            <Text h1>Example 5</Text>
          </TabView.Item>
        </TabView>
      </Tabs>
    </>
  );
};

@hugoseri
Copy link

hugoseri commented Jul 7, 2023

@arpitBhalla Thank you for the solution you provided. I implemented your example and the error presented above is not triggered anymore.

However, another one happens randomly for some reason I couldn't find yet.
The error looks like this:

ERROR  Invariant Violation: outputRange must have at least 2 elements

This error is located at:
    in Tab (created by OrdersScreen)

On the phone, I can get more details, as shown in the linked screenshot.

Screenshot 2023-07-07 at 15 52 51

When logging what is happening, in my node_modules/@rneui/base/dist/Tab/Tab.js I got issues in the TabBase function:

  • indicatorWidth is undefined,
  • tabItemsPositions.current contains the following: [undefined, {"position": 180.6666717529297, "width": 180.3333282470703}].


This leads for inputRange and outputRange to be respectively [1] and [NaN], explaining the next error from AnimatedInterpolation.js.

I can't find why indicatorWidth and tabItemsPositions.current hold such values at a given moment...

Hope it can help 🙏

@DarylBeattie
Copy link
Author

I also tested this example and I am getting sporadically the same "outputRange must have at least 2 elements". It doesn't always happen, but it does happen 10% of the time, approximately.

I have contacted Arpit with many details about my testing.

I also found this new code has some issues:

  • you must use the RNEUI's component, if you use ReactNative's component, the tabs crash the app.
  • the tabs do not show up at all without a "style" attribute that sets a height for the tabs.
  • there's hard-coded blue-backgrounds for the active-tab that you cannot get rid of.
  • it will crash if you use child components inside your component; you must have or as children.

@franamu
Copy link

franamu commented Aug 14, 2023

Hi any updates on this issue?

@michael-gates-techngs
Copy link

michael-gates-techngs commented Aug 15, 2023

I am also experiencing this issue.

translateX: isNaN(indicatorTransitionInterpolate) ? value * (WIDTH?WIDTH:0) : indicatorTransitionInterpolate,

For those wondering, you can make the suggested temp fix in node_modules/@rneui/base/dist/Tab/Tab.js:122

@DarylBeattie
Copy link
Author

Hi any updates on this issue?

@franamu A couple times @arpitBhalla has sent me some new code to test, and I have found issues with the fixes and reported back to him. So the short story is; this issue still exists.

In the meantime I have been using my temporary isNaN fix, and it works for me, though it is a hack-fix.

@Quiet-Hunter
Copy link

Quiet-Hunter commented Aug 20, 2023

Have the same issue. I don't like modifying anything in node_modules, so here is my hack...
Exploring the sources I noticed, that indicatorStyle overrides the buggy {translateX: indicatorTransitionInterpolate}.
So in my component with Tab I added:

const [indicatorX, setIndicatorX] = useState(0);
const windowWidth = Dimensions.get('window').width;
const tabWidth = windowWidth / TABS_LENGTH; // Specify your tabs amount

... And modified Tab props as the following:

onChange={e => {
setTab(e); // Whatever you do here
setIndicatorX(e * tabWidth); // Setting the right translateX value
}}
indicatorStyle={{
...mainStyles.tabIndicator, // Your custom styles if you have ones
transform: [{ translateX: indicatorX }], // Overriding the buggy string from the source
}}

Hope, it will help someone

@DarylBeattie
Copy link
Author

Sadly that solution doesn't work for me.
The underline for the tabs are too wide for the last tab and it stretches off the screen. Bummer.

Also, it requires me to add tab-specific code to all of the 7 screens that use my tabs, versus just changing 1 line in the Tab component in node_modules (which, I agree, I hate to do!) to get it to work everywhere.

@eddiechan0101
Copy link

translateX: isNaN(indicatorTransitionInterpolate) ? value * (WIDTH?WIDTH:0) : indicatorTransitionInterpolate,

It works for me. Thank you @DaryBeattie
But could you create a pr and merge these changes? So not to crash the app at least.

@BoyYangzai
Copy link

Hope it can be resolved quickly, thanks

@VirenMohindra
Copy link

I have temporarily stopped this error from crashing my app by changing Tab's indicator's Animated.View to transform to:

transform: [
    {
        translateX: isNaN(indicatorTransitionInterpolate) ? value * (WIDTH?WIDTH:0) : indicatorTransitionInterpolate,
    },
],

Hey, we encountered this issue and this fixed work for us. Hoping a PR can land soon.

@DarylBeattie
Copy link
Author

translateX: isNaN(indicatorTransitionInterpolate) ? value * (WIDTH?WIDTH:0) : indicatorTransitionInterpolate,

It works for me. Thank you @DaryBeattie But could you create a pr and merge these changes? So not to crash the app at least.

I don't know how to do this, or I would have done it months ago, yes...

The fix works locally, but when I build my app, the package bundler downloads the libraries from their source so my fix is not applied.
If this fix were committed to the repo, then it would apply to my built app as well.

Sadly, as a result, I have been ripping out the RNEUI Tabs from my app.......

@asawyers
Copy link

Have the same issue. I don't like modifying anything in node_modules, so here is my hack... Exploring the sources I noticed, that indicatorStyle overrides the buggy {translateX: indicatorTransitionInterpolate}. So in my component with Tab I added: const [indicatorX, setIndicatorX] = useState(0); const windowWidth = Dimensions.get('window').width; const tabWidth = windowWidth / TABS_LENGTH; // Specify your tabs amount ... And modified Tab props as the following: onChange={e => { setTab(e); // Whatever you do here setIndicatorX(e * tabWidth); // Setting the right translateX value }} indicatorStyle={{ ...mainStyles.tabIndicator, // Your custom styles if you have ones transform: [{ translateX: indicatorX }], // Overriding the buggy string from the source }} Hope, it will help someone

Came here to say this solution worked for me, and didn't involve modifying source code. Thank you!

@VariabileAleatoria
Copy link

Any update on a fix?

@maghidini
Copy link

While waiting for the fix I am using a ButtonGroup component instead of a Tab, but keeping the TabView underneath it.

@mkozmelj
Copy link

This is still an issue. Any update on a fix?

@Humad
Copy link

Humad commented Jan 31, 2024

This still seems to be an issue.

@DarylBeattie
Copy link
Author

Sadly that solution doesn't work for me. The underline for the tabs are too wide for the last tab and it stretches off the screen. Bummer.

I should point out that I did get this to work for me.
The issue was that I had to subtract the horizontal-padding from the tabWidth. For example, if I have paddingHorizontal: 10 for my tabs, then I need to subtract 2X that (10 for each side) and then it works, like this:

const tabWidth = windowWidth / TABS_LENGTH - 20; // Specify your tabs amount

@FernandoAOborges
Copy link

Patch for @rneui/base
I've implemented a patch for the @rneui/base package.
@rneui+base+4.0.0-rc.8.patch

@irahulvrma
Copy link

irahulvrma commented May 18, 2024

You can try this!!!

const MyTabs = () => {
const [index, setIndex] = useState(0);
const windowWidth = Dimensions.get('window').width;
const tabWidth = windowWidth / TABS_LENGTH;

<Tab
value={index}
onChange={(e) => setIndex(e)}
indicatorStyle={{
...styles.tabIndicator,
transform: [{ translateX: index * tabWidth }],
}}
variant="primary"
containerStyle={{
backgroundColor: '#fff',
}}
>
<Tab.Item
title="Present"
titleStyle={styles.tabTitle}
/>
<Tab.Item
title="Absent"
titleStyle={styles.tabTitle}
/>

const styles = StyleSheet.create({
tabIndicator: {
backgroundColor: '#ffbb50',
height: 3,
},
tabTitle: {
fontSize: 14,
color: 'black',
},
tabViewItem: {
backgroundColor: 'transparent',
width: '100%',
},
tabContent: {
justifyContent: 'center',
alignItems: 'center',
},
});

export default MyTabs;

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

Successfully merging a pull request may close this issue.