-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38546 from allroundexperts/fix-38372
feat: Add temporary focus to enabled option in workspace initial page
- Loading branch information
Showing
9 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type {ForwardedRef} from 'react'; | ||
import React, {forwardRef} from 'react'; | ||
import type {View} from 'react-native'; | ||
import {StyleSheet} from 'react-native'; | ||
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import MenuItem from './MenuItem'; | ||
import type {MenuItemProps} from './MenuItem'; | ||
|
||
type Props = MenuItemProps & { | ||
/** Should the menu item be highlighted? */ | ||
highlighted?: boolean; | ||
}; | ||
|
||
function HighlightableMenuItem({wrapperStyle, highlighted, ...restOfProps}: Props, ref: ForwardedRef<View>) { | ||
const styles = useThemeStyles(); | ||
|
||
const flattenedWrapperStyles = StyleSheet.flatten(wrapperStyle); | ||
const animatedHighlightStyle = useAnimatedHighlightStyle({ | ||
shouldHighlight: highlighted ?? false, | ||
height: flattenedWrapperStyles?.height ? Number(flattenedWrapperStyles.height) : styles.sectionMenuItem.height, | ||
borderRadius: flattenedWrapperStyles?.borderRadius ? Number(flattenedWrapperStyles.borderRadius) : styles.sectionMenuItem.borderRadius, | ||
}); | ||
|
||
return ( | ||
<MenuItem | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...restOfProps} | ||
outerWrapperStyle={animatedHighlightStyle} | ||
ref={ref} | ||
/> | ||
); | ||
} | ||
|
||
HighlightableMenuItem.displayName = 'HighlightableMenuItem'; | ||
|
||
export default forwardRef(HighlightableMenuItem); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const DELAY_FACTOR = 1.85; | ||
|
||
export default {}; | ||
|
||
export {DELAY_FACTOR}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {isMobile} from '@libs/Browser'; | ||
|
||
// It takes varying amount of time to navigate to a new page on mobile and desktop | ||
// This variable takes that into account | ||
const DELAY_FACTOR = isMobile() ? 1 : 0.2; | ||
export default {}; | ||
|
||
export {DELAY_FACTOR}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import {InteractionManager} from 'react-native'; | ||
import {Easing, interpolate, interpolateColor, runOnJS, useAnimatedStyle, useSharedValue, withDelay, withSequence, withTiming} from 'react-native-reanimated'; | ||
import useTheme from '@hooks/useTheme'; | ||
import CONST from '@src/CONST'; | ||
import {DELAY_FACTOR} from './config'; | ||
|
||
type Props = { | ||
/** Border radius of the wrapper */ | ||
borderRadius: number; | ||
|
||
/** Height of the item that is to be faded */ | ||
height: number; | ||
|
||
/** Whether the item should be highlighted */ | ||
shouldHighlight: boolean; | ||
|
||
/** Duration of the highlight animation */ | ||
highlightDuration?: number; | ||
|
||
/** Delay before the highlight animation starts */ | ||
delay?: number; | ||
}; | ||
|
||
/** | ||
* Returns a highlight style that interpolates the colour, height and opacity giving a fading effect. | ||
*/ | ||
export default function useAnimatedHighlightStyle({ | ||
borderRadius, | ||
shouldHighlight, | ||
highlightDuration = CONST.ANIMATED_HIGHLIGHT_DURATION, | ||
delay = CONST.ANIMATED_HIGHLIGHT_DELAY, | ||
height, | ||
}: Props) { | ||
const actualDelay = delay * DELAY_FACTOR; | ||
const repeatableProgress = useSharedValue(0); | ||
const nonRepeatableProgress = useSharedValue(shouldHighlight ? 0 : 1); | ||
const theme = useTheme(); | ||
|
||
const highlightBackgroundStyle = useAnimatedStyle(() => ({ | ||
backgroundColor: interpolateColor(repeatableProgress.value, [0, 1], ['rgba(0, 0, 0, 0)', theme.border]), | ||
height: interpolate(nonRepeatableProgress.value, [0, 1], [0, height]), | ||
opacity: interpolate(nonRepeatableProgress.value, [0, 1], [0, 1]), | ||
borderRadius, | ||
})); | ||
|
||
React.useEffect(() => { | ||
if (!shouldHighlight) { | ||
return; | ||
} | ||
|
||
InteractionManager.runAfterInteractions(() => { | ||
runOnJS(() => { | ||
nonRepeatableProgress.value = withDelay(actualDelay, withTiming(1, {duration: highlightDuration, easing: Easing.inOut(Easing.ease)})); | ||
repeatableProgress.value = withSequence( | ||
withDelay(actualDelay, withTiming(1, {duration: highlightDuration, easing: Easing.inOut(Easing.ease)})), | ||
withDelay(actualDelay, withTiming(0, {duration: highlightDuration, easing: Easing.inOut(Easing.ease)})), | ||
); | ||
})(); | ||
}); | ||
}, [shouldHighlight, highlightDuration, actualDelay, repeatableProgress, nonRepeatableProgress]); | ||
|
||
return highlightBackgroundStyle; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters