Skip to content

Commit

Permalink
chore: improve animation between tabs (#10422)
Browse files Browse the repository at this point in the history
  • Loading branch information
MounirDhahri committed Jun 21, 2024
1 parent c1fd2cf commit bb02dff
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions src/app/Scenes/BottomTabs/BottomTabsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { VisualClueName } from "app/store/config/visualClues"
import { switchTab } from "app/system/navigation/navigate"
import { useSelectedTab } from "app/utils/hooks/useSelectedTab"
import { useVisualClue } from "app/utils/hooks/useVisualClue"
import React, { useEffect, useRef, useState } from "react"
import { Animated, Easing, TouchableWithoutFeedback, View } from "react-native"
import { LayoutAnimation, TouchableWithoutFeedback, View } from "react-native"
import { useTracking } from "react-tracking"
import styled from "styled-components/native"
import { BottomTabOption, BottomTabType } from "./BottomTabType"
Expand All @@ -32,26 +31,13 @@ export const BottomTabsButton: React.FC<BottomTabsButtonProps> = ({
}) => {
const selectedTab = useSelectedTab()
const isActive = selectedTab === tab
const timeout = useRef<ReturnType<typeof setTimeout>>()
const [isBeingPressed, setIsBeingPressed] = useState(false)
const showActiveState = isActive || isBeingPressed

const activeProgress = useRef(new Animated.Value(showActiveState ? 1 : 0)).current

const { showVisualClue } = useVisualClue()

useEffect(() => {
Animated.timing(activeProgress, {
toValue: showActiveState ? 1 : 0,
useNativeDriver: true,
easing: Easing.ease,
duration: 100,
}).start()
}, [showActiveState])

const tracking = useTracking()

const onPress = () => {
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
if (tab === unsafe__getSelectedTab()) {
LegacyNativeModules.ARScreenPresenterModule.popToRootOrScrollToTop(tab)
} else {
Expand All @@ -71,17 +57,7 @@ export const BottomTabsButton: React.FC<BottomTabsButtonProps> = ({
accessibilityRole="button"
accessibilityLabel={`${tab} bottom tab`}
accessibilityState={{ selected: isActive }}
onPressIn={() => {
clearTimeout(timeout.current)
setIsBeingPressed(true)
}}
onPressOut={() => {
timeout.current = setTimeout(() => {
setIsBeingPressed(false)
}, 150)
}}
onPress={onPress}
onLongPress={onPress}
style={{ flex: 1 }}
>
<View style={{ flex: 1 }}>
Expand All @@ -92,16 +68,16 @@ export const BottomTabsButton: React.FC<BottomTabsButtonProps> = ({
<BottomTabsIcon tab={tab} state="inactive" />
</IconWrapper>
<IconWrapper>
<Animated.View
<View
style={{
opacity: activeProgress,
opacity: isActive ? 1 : 0,
backgroundColor: "white",
width: ICON_WIDTH,
height: ICON_HEIGHT,
}}
>
<BottomTabsIcon tab={tab} state="active" />
</Animated.View>
</View>
</IconWrapper>
</Flex>

Expand Down

0 comments on commit bb02dff

Please sign in to comment.