Improve the 'expand avis' animation in the notifications

zio/stable
Paul Frazee 2023-01-19 11:41:24 -06:00
parent d2db9baacc
commit 1c5c2622bf
1 changed files with 36 additions and 28 deletions

View File

@ -27,7 +27,6 @@ import {useAnimatedValue} from '../../lib/hooks/useAnimatedValue'
const MAX_AUTHORS = 8 const MAX_AUTHORS = 8
const EXPANDED_AUTHOR_EL_HEIGHT = 35 const EXPANDED_AUTHOR_EL_HEIGHT = 35
const EXPANDED_AUTHORS_CLOSE_EL_HEIGHT = 26
interface Author { interface Author {
href: string href: string
@ -163,16 +162,15 @@ export const FeedItem = observer(function FeedItem({
<TouchableWithoutFeedback <TouchableWithoutFeedback
onPress={authors.length > 1 ? onToggleAuthorsExpanded : () => {}}> onPress={authors.length > 1 ? onToggleAuthorsExpanded : () => {}}>
<View> <View>
<ExpandedAuthorsList <CondensedAuthorsList
visible={isAuthorsExpanded} visible={!isAuthorsExpanded}
authors={authors} authors={authors}
onToggleAuthorsExpanded={onToggleAuthorsExpanded} onToggleAuthorsExpanded={onToggleAuthorsExpanded}
/> />
{isAuthorsExpanded ? ( <ExpandedAuthorsList
<></> visible={isAuthorsExpanded}
) : ( authors={authors}
<CondensedAuthorsList authors={authors} /> />
)}
<View style={styles.meta}> <View style={styles.meta}>
<Link <Link
key={authors[0].href} key={authors[0].href}
@ -210,8 +208,34 @@ export const FeedItem = observer(function FeedItem({
) )
}) })
function CondensedAuthorsList({authors}: {authors: Author[]}) { function CondensedAuthorsList({
visible,
authors,
onToggleAuthorsExpanded,
}: {
visible: boolean
authors: Author[]
onToggleAuthorsExpanded: () => void
}) {
const pal = usePalette('default') const pal = usePalette('default')
if (!visible) {
return (
<View style={styles.avis}>
<TouchableOpacity
style={styles.expandedAuthorsCloseBtn}
onPress={onToggleAuthorsExpanded}>
<FontAwesomeIcon
icon="angle-up"
size={18}
style={[styles.expandedAuthorsCloseBtnIcon, pal.text]}
/>
<Text type="sm-medium" style={pal.text}>
Hide
</Text>
</TouchableOpacity>
</View>
)
}
if (authors.length === 1) { if (authors.length === 1) {
return ( return (
<View style={styles.avis}> <View style={styles.avis}>
@ -258,17 +282,14 @@ function CondensedAuthorsList({authors}: {authors: Author[]}) {
function ExpandedAuthorsList({ function ExpandedAuthorsList({
visible, visible,
authors, authors,
onToggleAuthorsExpanded,
}: { }: {
visible: boolean visible: boolean
authors: Author[] authors: Author[]
onToggleAuthorsExpanded: () => void
}) { }) {
const pal = usePalette('default') const pal = usePalette('default')
const heightInterp = useAnimatedValue(visible ? 1 : 0) const heightInterp = useAnimatedValue(visible ? 1 : 0)
const targetHeight = const targetHeight =
authors.length * (EXPANDED_AUTHOR_EL_HEIGHT + 10) /*10=margin*/ + authors.length * (EXPANDED_AUTHOR_EL_HEIGHT + 10) /*10=margin*/
EXPANDED_AUTHORS_CLOSE_EL_HEIGHT
const heightStyle = { const heightStyle = {
height: Animated.multiply(heightInterp, targetHeight), height: Animated.multiply(heightInterp, targetHeight),
overflow: 'hidden', overflow: 'hidden',
@ -282,18 +303,6 @@ function ExpandedAuthorsList({
}, [heightInterp, visible]) }, [heightInterp, visible])
return ( return (
<Animated.View style={(s.mb5, heightStyle)}> <Animated.View style={(s.mb5, heightStyle)}>
<TouchableOpacity
style={styles.expandedAuthorsCloseBtn}
onPress={onToggleAuthorsExpanded}>
<FontAwesomeIcon
icon="angle-up"
size={18}
style={[styles.expandedAuthorsCloseBtnIcon, pal.text]}
/>
<Text type="sm-medium" style={pal.text}>
Hide
</Text>
</TouchableOpacity>
{authors.map(author => ( {authors.map(author => (
<Link <Link
key={author.href} key={author.href}
@ -409,9 +418,8 @@ const styles = StyleSheet.create({
expandedAuthorsCloseBtn: { expandedAuthorsCloseBtn: {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
paddingTop: 8, paddingTop: 10,
height: EXPANDED_AUTHORS_CLOSE_EL_HEIGHT, paddingBottom: 6,
overflow: 'hidden',
}, },
expandedAuthorsCloseBtnIcon: { expandedAuthorsCloseBtnIcon: {
marginLeft: 4, marginLeft: 4,