prefetch
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {LayoutAnimation, Pressable, StyleSheet} from 'react-native'
|
import {LayoutAnimation, Pressable, StyleSheet} from 'react-native'
|
||||||
|
import {Image} from 'expo-image'
|
||||||
import {Camera_Stroke2_Corner0_Rounded as Camera} from '#/components/icons/Camera'
|
import {Camera_Stroke2_Corner0_Rounded as Camera} from '#/components/icons/Camera'
|
||||||
import {useSetAvatar} from '#/screens/Onboarding/StepProfile/index'
|
import {useSetAvatar} from '#/screens/Onboarding/StepProfile/index'
|
||||||
import {useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {usePhotoLibraryPermission} from 'lib/hooks/usePermissions'
|
import {usePhotoLibraryPermission} from 'lib/hooks/usePermissions'
|
||||||
import {openPicker} from 'lib/media/picker.shared'
|
import {openPicker} from 'lib/media/picker.shared'
|
||||||
import {openCropper} from 'lib/media/picker'
|
import {openCropper} from 'lib/media/picker'
|
||||||
import {compressIfNeeded} from 'lib/media/manip'
|
import {compressIfNeeded} from 'lib/media/manip'
|
||||||
import {isWeb} from 'platform/detection'
|
import {isNative, isWeb} from 'platform/detection'
|
||||||
|
|
||||||
export function SelectImageButton() {
|
export function SelectImageButton() {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
@@ -38,6 +39,13 @@ export function SelectImageButton() {
|
|||||||
image = await compressIfNeeded(image, 1000000)
|
image = await compressIfNeeded(image, 1000000)
|
||||||
|
|
||||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
||||||
|
|
||||||
|
// If we are on mobile, prefetching the image will load the image into memory before we try and display it,
|
||||||
|
// stopping any brief flickers.
|
||||||
|
if (isNative) {
|
||||||
|
await Image.prefetch(image.path)
|
||||||
|
}
|
||||||
|
|
||||||
setAvatar(prev => ({
|
setAvatar(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
image,
|
image,
|
||||||
@@ -50,10 +58,11 @@ export function SelectImageButton() {
|
|||||||
style={[
|
style={[
|
||||||
styles.imageContainer,
|
styles.imageContainer,
|
||||||
styles.paletteContainer,
|
styles.paletteContainer,
|
||||||
|
a.mr_2xl,
|
||||||
t.atoms.border_contrast_high,
|
t.atoms.border_contrast_high,
|
||||||
]}
|
]}
|
||||||
onPress={onCameraPress}>
|
onPress={onCameraPress}>
|
||||||
<Camera size="xl" style={[t.atoms.text_contrast_medium]} />
|
<Camera height={35} width={35} style={[t.atoms.text_contrast_medium]} />
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user