Skip to content

initial/default index is not respected #18

Description

@terfender

I have 2 tabs and would like to default it to the second scene/tab.
However, the library is rendering the first scene/tab.

Expecting to see SecondRoute on the first mount

import * as React from "react";
import { Text, View, useWindowDimensions } from "react-native";
import { TabView } from "reanimated-tab-view";

const FirstRoute = () => (
  <View style={{ flex: 1, backgroundColor: "#ff4081" }}>
    <Text>First</Text>
  </View>
);

const SecondRoute = () => (
  <View style={{ flex: 1, backgroundColor: "#673ab7" }}>
    <Text>Second</Text>
  </View>
);

const renderScene = ({ route }: { route: any }) => {
  switch (route.key) {
    case "first":
      return <FirstRoute />;
    case "second":
      return <SecondRoute />;
    default:
      return null;
  }
};

export function Tabs() {
  const layout = useWindowDimensions();

  const [index, setIndex] = React.useState(1);
  const [routes] = React.useState([
    { key: "first", title: "First" },
    { key: "second", title: "Second" },
  ]);

  return (
    <TabView
      navigationState={{ index, routes }}
      renderScene={renderScene}
      onIndexChange={setIndex}
      initialLayout={{ width: layout.width }}
    />
  );
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions