From 132f99346e8c53ee0c9b22dad1c39d3618e55a12 Mon Sep 17 00:00:00 2001 From: Hailey Date: Wed, 14 Feb 2024 15:29:11 -0800 Subject: [PATCH] scrollable horizontal flatlist on web --- src/components/icons/Times.tsx | 2 +- src/screens/Onboarding/StepProfile/index.tsx | 117 ++++++++++++++----- 2 files changed, 88 insertions(+), 31 deletions(-) diff --git a/src/components/icons/Times.tsx b/src/components/icons/Times.tsx index 3802a21202..678ac3fcb3 100644 --- a/src/components/icons/Times.tsx +++ b/src/components/icons/Times.tsx @@ -1,5 +1,5 @@ import {createSinglePathSVG} from './TEMPLATE' -export const PlusLarge_Stroke2_Corner0_Rounded = createSinglePathSVG({ +export const TimesLarge_Stroke2_Corner0_Rounded = createSinglePathSVG({ path: 'M4.293 4.293a1 1 0 0 1 1.414 0L12 10.586l6.293-6.293a1 1 0 1 1 1.414 1.414L13.414 12l6.293 6.293a1 1 0 0 1-1.414 1.414L12 13.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L10.586 12 4.293 5.707a1 1 0 0 1 0-1.414Z', }) diff --git a/src/screens/Onboarding/StepProfile/index.tsx b/src/screens/Onboarding/StepProfile/index.tsx index 377c9db33f..8acf07432c 100644 --- a/src/screens/Onboarding/StepProfile/index.tsx +++ b/src/screens/Onboarding/StepProfile/index.tsx @@ -3,6 +3,7 @@ import { FlatList, FlatListProps, LayoutAnimation, + LayoutChangeEvent, ListRenderItemInfo, Pressable, StyleSheet, @@ -22,7 +23,11 @@ import { Description, OnboardingControls, } from '#/screens/Onboarding/Layout' -import {ChevronRight_Stroke2_Corner0_Rounded as ChevronRight} from '#/components/icons/Chevron' +import { + ChevronLeft_Stroke2_Corner0_Rounded, + ChevronRight_Stroke2_Corner0_Rounded as ChevronRight, +} from '#/components/icons/Chevron' +import {TimesLarge_Stroke2_Corner0_Rounded as Times} from '#/components/icons/Times' import {IconCircle} from '#/components/IconCircle' import {Image} from 'expo-image' import {Emoji, EmojiName, emojiItems, emojiNames} from './types' @@ -31,8 +36,7 @@ import { PlaceholderCanvas, PlaceholderCanvasRef, } from '#/screens/Onboarding/StepProfile/PlaceholderCanvas' -import {Text} from '#/components/Typography' -import {HITSLOP_10} from 'lib/constants' +import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' interface Avatar { image?: { @@ -157,30 +161,29 @@ function AvatarCircle() { if (avatar.image) { return ( - + - - {/* TODO Get a trash icon for alf */} - x - - + ]} + onPress={onPressRemoveAvatar}> + + + ) } @@ -189,7 +192,9 @@ function AvatarCircle() { style={[ styles.imageContainer, t.atoms.border_contrast_high, - {backgroundColor: avatar.backgroundColor}, + { + backgroundColor: avatar.backgroundColor, + }, ]}> @@ -263,7 +268,7 @@ function EmojiItem({emojiName}: {emojiName: EmojiName}) { styles.paletteContainer, t.atoms.border_contrast_high, { - borderWidth: avatar.placeholder ? 4 : 2, + borderWidth: avatar.placeholder.name === emojiName ? 4 : 2, }, ]} onPress={onPress}> @@ -276,25 +281,76 @@ function emojiRenderItem({item}: ListRenderItemInfo) { } function Items({type}: {type: 'emojis' | 'colors'}) { - if (type === 'colors') { - return ( - - - data={colors} - renderItem={colorRenderItem} - {...commonFlatListProps} - /> - - ) - } + const t = useTheme() + const {isTabletOrDesktop} = useWebMediaQueries() + + const maxWidth = React.useRef(0) + const width = React.useRef(0) + const page = React.useRef(0) + const ref = React.useRef(null) + + const onLayout = React.useCallback((e: LayoutChangeEvent) => { + width.current = e.nativeEvent.layout.width + }, []) + + const onContentSizeChanged = React.useCallback((w: number, _: number) => { + maxWidth.current = w + }, []) + + const onLeftPress = React.useCallback(() => { + if (page.current === 0) return + page.current -= 1 + ref.current?.scrollToOffset({ + offset: width.current * page.current - width.current + 50, + }) + }, []) + + const onRightPress = React.useCallback(() => { + const newOffset = width.current * (page.current + 1) - 50 + if (newOffset >= maxWidth.current + width.current) return + + page.current += 1 + ref.current?.scrollToOffset({ + offset: newOffset, + }) + }, []) return ( - - data={emojiNames} - renderItem={emojiRenderItem} + {isTabletOrDesktop && ( + + + + )} + + {isTabletOrDesktop && ( + + + + )} ) } @@ -315,6 +371,8 @@ const styles = StyleSheet.create({ marginHorizontal: 5, }, flatListOuter: { + flexDirection: 'row', + alignItems: 'center', height: 100, }, flatListContainer: { @@ -325,6 +383,5 @@ const styles = StyleSheet.create({ const commonFlatListProps: Partial> = { horizontal: true, - contentContainerStyle: styles.flatListContainer, showsHorizontalScrollIndicator: false, }