forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into poc/split-navs
- Loading branch information
Showing
51 changed files
with
532 additions
and
504 deletions.
There are no files selected for viewing
Submodule Mobile-Expensify
updated
from 114af5 to b3fa66
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,81 @@ | ||
import type {ReactNode} from 'react'; | ||
import React from 'react'; | ||
import type {StyleProp, ViewStyle} from 'react-native'; | ||
import {View} from 'react-native'; | ||
import type {SharedValue} from 'react-native-reanimated'; | ||
import Animated, {Easing, useAnimatedStyle, useDerivedValue, useSharedValue, withTiming} from 'react-native-reanimated'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
||
type AccordionProps = { | ||
/** Giving information whether the component is open */ | ||
isExpanded: SharedValue<boolean>; | ||
|
||
/** Element that is inside Accordion */ | ||
children: ReactNode; | ||
|
||
/** Duration of expansion animation */ | ||
duration?: number; | ||
|
||
/** Additional external style */ | ||
style?: StyleProp<ViewStyle>; | ||
|
||
/** Was toggle triggered */ | ||
isToggleTriggered: SharedValue<boolean>; | ||
}; | ||
|
||
function Accordion({isExpanded, children, duration = 300, isToggleTriggered, style}: AccordionProps) { | ||
const height = useSharedValue(0); | ||
const styles = useThemeStyles(); | ||
|
||
const derivedHeight = useDerivedValue(() => { | ||
if (!isToggleTriggered.get()) { | ||
return isExpanded.get() ? height.get() : 0; | ||
} | ||
|
||
return withTiming(height.get() * Number(isExpanded.get()), { | ||
duration, | ||
easing: Easing.inOut(Easing.quad), | ||
}); | ||
}); | ||
|
||
const derivedOpacity = useDerivedValue(() => { | ||
if (!isToggleTriggered.get()) { | ||
return isExpanded.get() ? 1 : 0; | ||
} | ||
|
||
return withTiming(isExpanded.get() ? 1 : 0, { | ||
duration, | ||
easing: Easing.inOut(Easing.quad), | ||
}); | ||
}); | ||
|
||
const animatedStyle = useAnimatedStyle(() => { | ||
if (!isToggleTriggered.get() && !isExpanded.get()) { | ||
return { | ||
height: 0, | ||
opacity: 0, | ||
}; | ||
} | ||
return { | ||
height: !isToggleTriggered.get() ? height.get() : derivedHeight.get(), | ||
opacity: derivedOpacity.get(), | ||
}; | ||
}); | ||
|
||
return ( | ||
<Animated.View style={[animatedStyle, style]}> | ||
<View | ||
onLayout={(e) => { | ||
height.set(e.nativeEvent.layout.height); | ||
}} | ||
style={[styles.pAbsolute, styles.l0, styles.r0, styles.t0]} | ||
> | ||
{children} | ||
</View> | ||
</Animated.View> | ||
); | ||
} | ||
|
||
Accordion.displayName = 'Accordion'; | ||
|
||
export default Accordion; |
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,78 @@ | ||
import type {ReactNode} from 'react'; | ||
import React from 'react'; | ||
import type {StyleProp, ViewStyle} from 'react-native'; | ||
import {View} from 'react-native'; | ||
import type {SharedValue} from 'react-native-reanimated'; | ||
import Animated, {Easing, useAnimatedStyle, useDerivedValue, useSharedValue, withTiming} from 'react-native-reanimated'; | ||
|
||
type AccordionProps = { | ||
/** Giving information whether the component is open */ | ||
isExpanded: SharedValue<boolean>; | ||
|
||
/** Element that is inside Accordion */ | ||
children: ReactNode; | ||
|
||
/** Duration of expansion animation */ | ||
duration?: number; | ||
|
||
/** Additional external style */ | ||
style?: StyleProp<ViewStyle>; | ||
|
||
/** Was toggle triggered */ | ||
isToggleTriggered: SharedValue<boolean>; | ||
}; | ||
|
||
function Accordion({isExpanded, children, duration = 300, isToggleTriggered, style}: AccordionProps) { | ||
const height = useSharedValue(0); | ||
|
||
const derivedHeight = useDerivedValue(() => { | ||
if (!isToggleTriggered.get()) { | ||
return isExpanded.get() ? height.get() : 0; | ||
} | ||
|
||
return withTiming(height.get() * Number(isExpanded.get()), { | ||
duration, | ||
easing: Easing.inOut(Easing.quad), | ||
}); | ||
}); | ||
|
||
const derivedOpacity = useDerivedValue(() => { | ||
if (!isToggleTriggered.get()) { | ||
return isExpanded.get() ? 1 : 0; | ||
} | ||
|
||
return withTiming(isExpanded.get() ? 1 : 0, { | ||
duration, | ||
easing: Easing.inOut(Easing.quad), | ||
}); | ||
}); | ||
|
||
const animatedStyle = useAnimatedStyle(() => { | ||
if (!isToggleTriggered.get() && !isExpanded.get()) { | ||
return { | ||
height: 0, | ||
opacity: 0, | ||
}; | ||
} | ||
|
||
return { | ||
height: !isToggleTriggered.get() ? undefined : derivedHeight.get(), | ||
opacity: derivedOpacity.get(), | ||
}; | ||
}); | ||
|
||
return ( | ||
<Animated.View style={[animatedStyle, style]}> | ||
<View | ||
onLayout={(e) => { | ||
height.set(e.nativeEvent.layout.height); | ||
}} | ||
> | ||
{children} | ||
</View> | ||
</Animated.View> | ||
); | ||
} | ||
Accordion.displayName = 'Accordion'; | ||
|
||
export default Accordion; |
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
Oops, something went wrong.