working on both platforms

This commit is contained in:
Hailey
2024-02-13 22:45:59 -08:00
parent 4ac53f168a
commit f529738227
4 changed files with 36 additions and 18 deletions
+5 -1
View File
@@ -34,9 +34,13 @@ export async function uploadBlob(
): Promise<ComAtprotoRepoUploadBlob.Response> { ): Promise<ComAtprotoRepoUploadBlob.Response> {
if (isWeb) { if (isWeb) {
// `blob` should be a data uri // `blob` should be a data uri
return agent.uploadBlob(convertDataURIToUint8Array(blob), { console.log(convertDataURIToUint8Array(blob))
const x = await agent.uploadBlob(convertDataURIToUint8Array(blob), {
encoding, encoding,
}) })
return x
} else { } else {
// `blob` should be a path to a file in the local FS // `blob` should be a path to a file in the local FS
return agent.uploadBlob( return agent.uploadBlob(
+4 -2
View File
@@ -78,10 +78,12 @@ export function StepFinished() {
const res = await uploadBlob( const res = await uploadBlob(
getAgent(), getAgent(),
profileStepResults.imageUri, profileStepResults.imageUri,
profileStepResults.imageUri, profileStepResults.imageMime,
) )
existing.avatar = res.data.blob if (res.data.blob) {
existing.avatar = res.data.blob
}
} }
return existing return existing
@@ -1,10 +1,11 @@
import React from 'react' import React from 'react'
import {useAvatar} from '#/screens/Onboarding/StepProfile/index' import {useAvatar} from '#/screens/Onboarding/StepProfile/index'
import {StyleSheet, View} from 'react-native'
const CANVAS_HEIGHT = 24 * 10 const CANVAS_HEIGHT = 24 * 20
const CANVAS_OFFSET = 24 * 1.5 const CANVAS_OFFSET = 24 * 3
interface PlaceholderCanvasRef { export interface PlaceholderCanvasRef {
capture: () => string capture: () => string
} }
@@ -16,7 +17,7 @@ export const PlaceholderCanvas = React.forwardRef(function PlaceholderCanvas(
const canvasRef = React.useRef<HTMLCanvasElement>(null) const canvasRef = React.useRef<HTMLCanvasElement>(null)
const capture = React.useCallback(() => { const capture = React.useCallback(() => {
return '' return canvasRef.current?.toDataURL('image/jpeg')
}, []) }, [])
React.useImperativeHandle(ref, () => ({ React.useImperativeHandle(ref, () => ({
@@ -35,9 +36,20 @@ export const PlaceholderCanvas = React.forwardRef(function PlaceholderCanvas(
ctx.fillStyle = '#fff' ctx.fillStyle = '#fff'
ctx.lineWidth = 0.1 ctx.lineWidth = 0.1
ctx?.translate(CANVAS_OFFSET, CANVAS_OFFSET) ctx?.translate(CANVAS_OFFSET, CANVAS_OFFSET)
ctx?.scale(7, 7) ctx?.scale(14, 14)
ctx?.fill(path) ctx?.fill(path)
}, [avatar.backgroundColor, avatar.placeholder.path]) }, [avatar.backgroundColor, avatar.placeholder.path])
return <canvas ref={canvasRef} height={CANVAS_HEIGHT} width={CANVAS_HEIGHT} /> return (
<View style={styles.container}>
<canvas ref={canvasRef} height={CANVAS_HEIGHT} width={CANVAS_HEIGHT} />
</View>
)
})
const styles = StyleSheet.create({
container: {
top: -2000,
position: 'absolute',
},
}) })
+9 -9
View File
@@ -66,15 +66,15 @@ export function StepProfile() {
const canvasRef = React.useRef<PlaceholderCanvasRef>(null) const canvasRef = React.useRef<PlaceholderCanvasRef>(null)
React.useEffect(() => { // React.useEffect(() => {
// TODO remove, this is for testing // // TODO remove, this is for testing
;(async () => { // ;(async () => {
const res = await canvasRef.current?.capture() // const res = await canvasRef.current?.capture()
if (res) { // if (res) {
setUri(res) // setUri(res)
} // }
})() // })()
}, [avatar]) // }, [avatar])
React.useEffect(() => { React.useEffect(() => {
track('OnboardingV2:StepProfile:Start') track('OnboardingV2:StepProfile:Start')