Skip to content

Commit 283d909

Browse files
committed
fix(polyfills): migrate to new expo-file-system API for Expo 54
1 parent 9ca5264 commit 283d909

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"eslint-plugin-react": "^7.29.4",
7070
"eslint-plugin-react-hooks": "^4.4.0",
7171
"expo-asset": "^8.6.0",
72-
"expo-file-system": "^15.4.3",
72+
"expo-file-system": "^19.0.17",
7373
"expo-gl": "^11.4.0",
7474
"husky": "^7.0.4",
7575
"jest": "^29.7.0",
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
export const EncodingType = { UTF8: 'utf8', Base64: 'base64' }
2-
export const cacheDirectory = 'file:///test/'
3-
export const readAsStringAsync = async () => ''
4-
export const writeAsStringAsync = async () => {}
5-
export const copyAsync = async () => {}
1+
export const Paths = { cache: { uri: 'file:///test/' } }
2+
export class File {
3+
async write(data: string) {}
4+
async base64() {
5+
return ''
6+
}
7+
async copy(to: File) {}
8+
}

packages/fiber/src/native/polyfills.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ async function getAsset(input: string | number): Promise<string> {
4646
const [header, data] = input.split(';base64,')
4747
const [, type] = header.split('/')
4848

49-
const uri = fs.cacheDirectory + uuidv4() + `.${type}`
50-
await fs.writeAsStringAsync(uri, data, { encoding: fs.EncodingType.Base64 })
49+
const uri = fs.Paths.cache.uri + uuidv4() + `.${type}`
50+
await new fs.File(uri).write(data, { encoding: 'base64' })
5151

5252
return uri
5353
}
@@ -59,8 +59,8 @@ async function getAsset(input: string | number): Promise<string> {
5959

6060
// Unpack assets in Android Release Mode
6161
if (!uri.includes(':')) {
62-
const file = `${fs.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`
63-
await fs.copyAsync({ from: uri, to: file })
62+
const file = `${fs.Paths.cache.uri}ExponentAsset-${asset.hash}.${asset.type}`
63+
await new fs.File(uri).copy(new fs.File(file))
6464
uri = file
6565
}
6666

@@ -160,7 +160,7 @@ export function polyfills() {
160160

161161
getAsset(url)
162162
.then(async (uri) => {
163-
const base64 = await fs.readAsStringAsync(uri, { encoding: fs.EncodingType.Base64 })
163+
const base64 = await new fs.File(uri).base64()
164164
const data = Buffer.from(base64, 'base64')
165165
onLoad?.(data.buffer)
166166
})

packages/fiber/tests/polyfills.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ describe('polyfills', () => {
2121

2222
it('unpacks drawables in Android APK', async () => {
2323
const texture = await new THREE.TextureLoader().loadAsync('drawable.png')
24+
console.log('texture.image.data', texture.image.data)
25+
console.log('texture.image.data.localUri', texture.image.data.localUri)
2426
expect(texture.image.data.localUri.includes(':')).toBe(true)
2527
})
2628

yarn.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5155,7 +5155,12 @@ expo-constants@~15.3.0:
51555155
"@expo/config" "~8.4.0"
51565156
uuid "^3.3.2"
51575157

5158-
expo-file-system@^15.4.3, expo-file-system@~15.9.0:
5158+
expo-file-system@^19.0.17:
5159+
version "19.0.17"
5160+
resolved "https://registry.yarnpkg.com/expo-file-system/-/expo-file-system-19.0.17.tgz#2555c05c26a19038d005f281b11dbda9722d0c0d"
5161+
integrity sha512-WwaS01SUFrxBnExn87pg0sCTJjZpf2KAOzfImG0o8yhkU7fbYpihpl/oocXBEsNbj58a8hVt1Y4CVV5c1tzu/g==
5162+
5163+
expo-file-system@~15.9.0:
51595164
version "15.9.0"
51605165
resolved "https://registry.yarnpkg.com/expo-file-system/-/expo-file-system-15.9.0.tgz#b048b9168875634efcce0aa002ee0eec31ed42a8"
51615166
integrity sha512-ikzqBGpbSzp/57+aruXzRR2s0HEVYxdd1o3RxfswJRujjT/6X128xmUTTFDaQUr+zydyvxvY7Mo0szWpXhPyLA==

0 commit comments

Comments
 (0)