canvas working 🎉
This commit is contained in:
@@ -3,42 +3,56 @@ import {useAvatar} from '#/screens/Onboarding/StepProfile/index'
|
|||||||
import ViewShot from 'react-native-view-shot'
|
import ViewShot from 'react-native-view-shot'
|
||||||
import {StyleSheet, View} from 'react-native'
|
import {StyleSheet, View} from 'react-native'
|
||||||
|
|
||||||
|
export interface PlaceholderCanvasRef {
|
||||||
|
capture: () => Promise<string>
|
||||||
|
}
|
||||||
|
|
||||||
// This component is supposed to be invisible to the user. We only need this for ViewShot to have something to
|
// This component is supposed to be invisible to the user. We only need this for ViewShot to have something to
|
||||||
// "screenshot"
|
// "screenshot".
|
||||||
export const PlaceholderCanvas = React.forwardRef(function PlaceholderCanvas(
|
export const PlaceholderCanvas = React.forwardRef<PlaceholderCanvasRef, {}>(
|
||||||
{},
|
function PlaceholderCanvas({}, ref) {
|
||||||
ref,
|
const avatar = useAvatar()
|
||||||
) {
|
const viewshotRef = React.useRef()
|
||||||
const avatar = useAvatar()
|
const Icon = avatar.placeholder.component
|
||||||
const viewshotRef = React.useRef()
|
|
||||||
const Icon = avatar.placeholder.component
|
|
||||||
|
|
||||||
// React.useEffect(() => {
|
React.useImperativeHandle(ref, () => ({
|
||||||
// // @ts-ignore this library doesn't have types
|
// @ts-ignore this library doesn't have types
|
||||||
// viewshotRef.current.capture().then(uri => {
|
capture: viewshotRef.current.capture,
|
||||||
// return uri
|
}))
|
||||||
// })
|
|
||||||
// }, [avatar, ref])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.imageContainer}>
|
<View style={styles.container}>
|
||||||
<ViewShot
|
<ViewShot
|
||||||
ref={viewshotRef}
|
// @ts-ignore this library doesn't have types
|
||||||
options={{fileName: 'placeholderAvatar', format: 'jpg', quality: 1.0}}>
|
ref={viewshotRef}
|
||||||
<View
|
options={{
|
||||||
style={[{backgroundColor: avatar.backgroundColor}]}
|
fileName: 'placeholderAvatar',
|
||||||
collapsable={false}>
|
format: 'jpg',
|
||||||
<Icon height={500} width={500} style={{color: 'white'}} />
|
quality: 1.0,
|
||||||
</View>
|
}}>
|
||||||
</ViewShot>
|
<View
|
||||||
</View>
|
style={[
|
||||||
)
|
styles.imageContainer,
|
||||||
})
|
{backgroundColor: avatar.backgroundColor},
|
||||||
|
]}
|
||||||
|
collapsable={false}>
|
||||||
|
<Icon height={85 * 5} width={85 * 5} style={{color: 'white'}} />
|
||||||
|
</View>
|
||||||
|
</ViewShot>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
imageContainer: {
|
container: {
|
||||||
top: 100,
|
top: -2000,
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
zIndex: -5,
|
},
|
||||||
|
imageContainer: {
|
||||||
|
height: 150 * 5,
|
||||||
|
width: 150 * 5,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -32,7 +32,10 @@ import {openCropper, openPicker} from 'lib/media/picker'
|
|||||||
import {Emoji, EmojiName, emojiItems, emojiNames} from './types'
|
import {Emoji, EmojiName, emojiItems, emojiNames} from './types'
|
||||||
import {SelectImageButton} from '#/screens/Onboarding/StepProfile/SelectImageButton'
|
import {SelectImageButton} from '#/screens/Onboarding/StepProfile/SelectImageButton'
|
||||||
import ViewShot from 'react-native-view-shot'
|
import ViewShot from 'react-native-view-shot'
|
||||||
import {PlaceholderCanvas} from '#/screens/Onboarding/StepProfile/PlaceholderCanvas'
|
import {
|
||||||
|
PlaceholderCanvas,
|
||||||
|
PlaceholderCanvasRef,
|
||||||
|
} from '#/screens/Onboarding/StepProfile/PlaceholderCanvas'
|
||||||
|
|
||||||
interface Avatar {
|
interface Avatar {
|
||||||
image?: {
|
image?: {
|
||||||
@@ -63,6 +66,19 @@ export function StepProfile() {
|
|||||||
placeholder: emojiItems.smile,
|
placeholder: emojiItems.smile,
|
||||||
backgroundColor: '#338388',
|
backgroundColor: '#338388',
|
||||||
})
|
})
|
||||||
|
const [uri, setUri] = React.useState('')
|
||||||
|
|
||||||
|
const canvasRef = React.useRef<PlaceholderCanvasRef>(null)
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
// TODO remove, this is for testing
|
||||||
|
;(async () => {
|
||||||
|
const res = await canvasRef.current?.capture()
|
||||||
|
if (res) {
|
||||||
|
setUri(res)
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
}, [avatar])
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
track('OnboardingV2:StepProfile:Start')
|
track('OnboardingV2:StepProfile:Start')
|
||||||
@@ -97,6 +113,8 @@ export function StepProfile() {
|
|||||||
</View>
|
</View>
|
||||||
<Items type="emojis" />
|
<Items type="emojis" />
|
||||||
<Items type="colors" />
|
<Items type="colors" />
|
||||||
|
{/* TOOD remove, testing */}
|
||||||
|
<Image source={uri} style={{height: 100, width: 100}} />
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<OnboardingControls.Portal>
|
<OnboardingControls.Portal>
|
||||||
@@ -114,7 +132,7 @@ export function StepProfile() {
|
|||||||
</Button>
|
</Button>
|
||||||
</OnboardingControls.Portal>
|
</OnboardingControls.Portal>
|
||||||
</View>
|
</View>
|
||||||
<PlaceholderCanvas />
|
<PlaceholderCanvas ref={canvasRef} />
|
||||||
</>
|
</>
|
||||||
</AvatarContext.Provider>
|
</AvatarContext.Provider>
|
||||||
</SetAvatarContext.Provider>
|
</SetAvatarContext.Provider>
|
||||||
@@ -140,6 +158,7 @@ function AvatarCircle() {
|
|||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
styles.imageContainer,
|
styles.imageContainer,
|
||||||
|
t.atoms.border_contrast_high,
|
||||||
{backgroundColor: avatar.backgroundColor},
|
{backgroundColor: avatar.backgroundColor},
|
||||||
]}>
|
]}>
|
||||||
<Icon height={85} width={85} style={{color: 'white'}} />
|
<Icon height={85} width={85} style={{color: 'white'}} />
|
||||||
@@ -256,7 +275,7 @@ const styles = StyleSheet.create({
|
|||||||
height: 150,
|
height: 150,
|
||||||
width: 150,
|
width: 150,
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
borderWidth: 1,
|
borderWidth: 2,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user