Skip to content

Commit 86c93a7

Browse files
Merge pull request #67 from binarapps/chore/expo-image-flashlist
Chore/expo image and FlashList
2 parents c9d77cb + 881da26 commit 86c93a7

26 files changed

+312
-216
lines changed

docs/docs/data-management/API-EXAMPLE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import { ArticleEntity } from '@baca/api/types'
2727
import { Loader, Center, Text, Box, Spacer } from '@baca/design-system'
2828
import { useScreenOptions, useTranslation } from '@baca/hooks'
2929
import { useCallback } from 'react'
30-
import { ListRenderItem, FlatList } from 'react-native'
30+
import { FlashList } from '@shopify/flash-list'
31+
import { ListRenderItem } from 'react-native'
3132

3233
export const DataFromBeScreen_EXAMPLE = () => {
3334
const { t } = useTranslation()
@@ -56,7 +57,7 @@ export const DataFromBeScreen_EXAMPLE = () => {
5657
<Text.XlRegular>THIS IS EXAMPLE SCREEN</Text.XlRegular>
5758
<Text.XlRegular>which contains data from backend</Text.XlRegular>
5859
<Spacer y="1" />
59-
<FlatList
60+
<FlashList
6061
ListEmptyComponent={
6162
!isInitialLoadingArticles ? (
6263
<Center height={400} flex={1}>

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"@react-navigation/native": "^6.1.9",
107107
"@react-navigation/native-stack": "^6.9.17",
108108
"@react-navigation/stack": "^6.3.20",
109+
"@shopify/flash-list": "1.6.4",
109110
"@tanstack/react-query": "^4.29.19",
110111
"axios": "^1.7.2",
111112
"core-js": "^3.37.1",
@@ -121,6 +122,7 @@
121122
"expo-device": "~6.0.2",
122123
"expo-font": "~12.0.5",
123124
"expo-haptics": "~13.0.1",
125+
"expo-image": "~1.12.12",
124126
"expo-image-picker": "~15.0.5",
125127
"expo-linear-gradient": "~13.0.2",
126128
"expo-linking": "~6.3.1",

src/components/COMPONENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ FAB.Group
124124
Fail // Toast
125125
FieldWrapper
126126
FlatList
127+
FlashList
127128
Flex // TODO:
128129
FloatingMenu
129130
Form // TODO:

src/components/CompanyLogo.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { darkBinarLogo, darkLogoSygnet, lightBinarLogo, lightLogoSygnet } from '@baca/constants'
22
import { ColorSchemeName, useColorScheme } from '@baca/contexts'
3-
import { Image, ImageProps, ImageStyle } from 'react-native'
3+
import { Image, ImageStyle, ImageProps } from 'expo-image'
44

55
type LogoTypes = 'binarSygnet' | 'binar'
66

@@ -26,12 +26,5 @@ export const CompanyLogo = ({
2626

2727
const source = LOGO[colorScheme][type]
2828

29-
return (
30-
<Image
31-
{...{ source }}
32-
resizeMethod="resize"
33-
resizeMode="contain"
34-
style={[{ height, maxWidth: width }, style]}
35-
/>
36-
)
29+
return <Image contentFit="scale-down" source={source} style={[{ height, width }, style]} />
3730
}

src/components/LandingHeader.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { useFullScreenModal } from '@baca/design-system/modals/useFullScreenModa
55
import { useCallback, useMemo, useTheme, useTranslation } from '@baca/hooks'
66
import { useUniversalWidth } from '@baca/navigation/tabNavigator/hooks'
77
import { isSignedInAtom } from '@baca/store/auth'
8+
import { Image } from 'expo-image'
89
import { useRouter } from 'expo-router'
910
import { useAtomValue } from 'jotai'
10-
import { Image, StyleSheet, Platform, View } from 'react-native'
11+
import { StyleSheet, Platform, View } from 'react-native'
1112
import { useSafeAreaInsets } from 'react-native-safe-area-context'
1213

1314
export function LandingHeader() {
@@ -36,8 +37,7 @@ export function LandingHeader() {
3637
</Pressable>
3738
) : (
3839
<Image
39-
resizeMethod="resize"
40-
resizeMode="contain"
40+
contentFit="scale-down"
4141
source={colorScheme === 'light' ? lightBinarLogo : darkBinarLogo}
4242
style={jsStyles.logoWide}
4343
/>

src/components/Modal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
View,
99
ViewStyle,
1010
StyleSheet,
11+
Dimensions,
1112
} from 'react-native'
1213

1314
import { KeyboardAwareScrollView } from './KeyboardAwareScrollView'
@@ -68,6 +69,6 @@ const styles = StyleSheet.create({
6869
},
6970
scrollContent: {
7071
justifyContent: 'center',
71-
paddingHorizontal: 32,
72+
paddingHorizontal: Dimensions.get('window').width < 450 ? 16 : 32,
7273
},
7374
})

src/components/molecules/Field/Radio.tsx

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@ import {
22
FormErrorMessage,
33
FormLabel,
44
Box,
5-
Touchable,
6-
Text,
75
TouchableRef,
6+
RadioButton,
87
} from '@baca/design-system/components'
9-
import { forwardRef, useCallback, useMemo } from 'react'
8+
import { forwardRef, useMemo } from 'react'
109

1110
import { FieldRadioProps } from './types'
1211

13-
const radioSizes = {
14-
sm: {
15-
boxSize: 4,
16-
},
17-
md: {
18-
boxSize: 5,
19-
},
20-
} as const
21-
2212
export const Radio = forwardRef<TouchableRef, FieldRadioProps>(
2313
(
2414
{
@@ -27,60 +17,32 @@ export const Radio = forwardRef<TouchableRef, FieldRadioProps>(
2717
radioOptions,
2818
errorMessage,
2919
isError,
30-
size = 'sm',
20+
size = 'md',
3121
onChange,
3222
label,
3323
labelStyle,
3424
isDisabled,
3525
},
3626
ref
3727
) => {
38-
const checkboxSize = useMemo(() => radioSizes[size], [size])
39-
40-
const getBorderColor = useCallback(
41-
(isSelected: boolean): ColorNames | undefined => {
42-
if (isDisabled) {
43-
return 'border.disabled'
44-
}
45-
if (isError) {
46-
return 'border.error'
47-
}
48-
49-
if (isSelected) {
50-
return 'bg.brand.solid'
51-
}
52-
53-
return 'border.primary'
54-
},
55-
[isDisabled, isError]
56-
)
57-
5828
const renderRadioButtons = useMemo(
5929
() =>
6030
radioOptions?.map((item: string, index: number) => {
6131
return (
62-
<Touchable
32+
<RadioButton
6333
ref={ref}
6434
key={index}
65-
onPress={() => onChange(item)}
66-
alignItems="center"
67-
flexDirection="row"
68-
height={8}
69-
>
70-
<Box
71-
alignItems="center"
72-
borderRadius={50}
73-
height={checkboxSize.boxSize}
74-
width={checkboxSize.boxSize}
75-
justifyContent="center"
76-
borderColor={getBorderColor(item === value)}
77-
borderWidth={item === value ? 5 : 1}
78-
/>
79-
<Text ml={4}>{item}</Text>
80-
</Touchable>
35+
isDisabled={isDisabled}
36+
isError={isError}
37+
isSelected={item === value}
38+
onChange={() => onChange(item)}
39+
pb={2}
40+
label={item}
41+
size={size}
42+
/>
8143
)
8244
}),
83-
[radioOptions, ref, checkboxSize.boxSize, getBorderColor, value, onChange]
45+
[radioOptions, ref, isDisabled, isError, value, size, onChange]
8446
)
8547

8648
return (

src/components/molecules/Field/Select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const Select = <T extends SelectKey>({
5858
<Box {...layoutProps} width="100%" mb={2}>
5959
<Pressable>
6060
<FormLabel label={label} isRequired={isRequired} labelStyle={labelStyle} />
61-
<CustomSelect {...props} />
61+
<CustomSelect label={label} {...props} />
6262
<FormErrorMessage errorMessage={errorMessage} />
6363
</Pressable>
6464
</Box>

src/components/molecules/Field/types.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
CheckboxProps,
3-
FormLabelProps,
4-
InputProps,
5-
RadioProps,
6-
SelectProps,
7-
} from '@baca/design-system'
1+
import { CheckboxProps, FormLabelProps, InputProps, SelectProps } from '@baca/design-system'
82

93
export type FieldInputProps = InputProps &
104
FormLabelProps & {
@@ -14,14 +8,18 @@ export type FieldInputProps = InputProps &
148
onFocus?: () => void
159
}
1610

17-
export type FieldRadioProps = RadioProps &
18-
FormLabelProps & {
19-
radioOptions?: string[]
20-
errorMessage?: string
21-
isInvalid?: boolean
22-
isDisabled?: boolean
23-
name: string
24-
}
11+
export type FieldRadioProps = FormLabelProps & {
12+
radioOptions?: string[]
13+
errorMessage?: string
14+
isInvalid?: boolean
15+
isDisabled?: boolean
16+
name: string
17+
onChange: (val: string) => void
18+
label?: string
19+
isError?: boolean
20+
value?: string | number
21+
size?: 'sm' | 'md'
22+
}
2523

2624
export type FieldSelectProps<T> = SelectProps<T> &
2725
FormLabelProps & {

src/components/molecules/SocialButtons/SocialButton.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { googleIcon } from '@baca/constants'
22
import { useColorScheme } from '@baca/contexts'
33
import { Button, ButtonProps, Icon } from '@baca/design-system'
44
import i18n from '@baca/i18n'
5+
import { Image, ImageStyle, ImageSource } from 'expo-image'
56
import { FC, useCallback } from 'react'
6-
import { Image, ImageSourcePropType } from 'react-native'
77

88
type SocialMediaType = 'apple' | 'facebook' | 'google'
99

1010
const socialButtonVariants: {
1111
[key in SocialMediaType]: {
12-
source?: { light: ImageSourcePropType; dark?: ImageSourcePropType }
12+
source?: { light: ImageSource; dark?: ImageSource }
1313
text: () => string
1414
}
1515
} = {
@@ -51,7 +51,10 @@ export const SocialButton: FC<SocialButtonProps> = ({ type = 'google', ...rest }
5151
return <Icon color="#1877F2" name="facebook-circle-fill" size={24} />
5252
case 'google':
5353
return (
54-
<Image source={source?.[colorScheme] || source?.['light']} width={24} height={24} />
54+
<Image
55+
source={source?.[colorScheme] || source?.['light']}
56+
style={{ width: 24, height: 24 } as ImageStyle}
57+
/>
5558
)
5659
}
5760
},

0 commit comments

Comments
 (0)