Skip to content

Commit

Permalink
revert currentTabIndex state in TabViewAva (#914)
Browse files Browse the repository at this point in the history
  • Loading branch information
onghwan authored Sep 12, 2023
1 parent d205a79 commit c1e2ab9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/components/TabViewAva.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useCallback, useMemo } from 'react'
import React, { FC, useCallback, useEffect, useMemo, useState } from 'react'
import {
NavigationState,
SceneRendererProps,
Expand Down Expand Up @@ -47,12 +47,16 @@ const TabViewAva: TabViewAvaFC = ({
lazy = true,
children
}) => {
const [currentIndex, setCurrentIndex] = useState(currentTabIndex)
const theme = useApplicationContext().theme

const childrenArray = useMemo(
() => React.Children.toArray(children),
[children]
)
useEffect(() => {
setCurrentIndex(currentTabIndex)
}, [currentTabIndex])
// https://github.com/satya164/react-native-tab-view#tabview-props
const routes = useMemo(
() =>
Expand All @@ -73,8 +77,8 @@ const TabViewAva: TabViewAvaFC = ({
)

const navState = useMemo(() => {
return { index: currentTabIndex, routes }
}, [currentTabIndex, routes])
return { index: currentIndex, routes }
}, [currentIndex, routes])

const scenes = useCallback(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -86,6 +90,7 @@ const TabViewAva: TabViewAvaFC = ({

const handleIndexChange = useCallback(
(index: number) => {
setCurrentIndex(index)
onTabIndexChange?.(index)
},
[onTabIndexChange]
Expand Down

0 comments on commit c1e2ab9

Please sign in to comment.