Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fabric migration - Testing new arch #3106

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
20a0ffc
remove unused packages, switch to `expo-linear-gradient`
haileyok Mar 4, 2024
a43dca9
upgrade expo deps
haileyok Mar 4, 2024
5219f66
rm blur view
haileyok Mar 4, 2024
654019c
re-add normalize-url
haileyok Mar 4, 2024
abaa796
replace `react-native-version-number` with `expo-application`
haileyok Mar 4, 2024
ff3a039
add `expo-haptics`
haileyok Mar 5, 2024
48914de
rm `react-native-haptic-feedback`
haileyok Mar 5, 2024
2d4d66e
migrate to `expo-haptics`
haileyok Mar 5, 2024
440ae91
add `expo-clipboard`
haileyok Mar 5, 2024
df5fb80
migrate to `expo-clipboard`
haileyok Mar 5, 2024
c0fe0c9
add `expo-file-system`
haileyok Mar 5, 2024
05cc3b6
migrate to `expo-file-system` and `expo-image-manipulator`
haileyok Mar 5, 2024
ad7e858
delete file after uploading blob on native
haileyok Mar 5, 2024
e91371b
fix file move error
haileyok Mar 5, 2024
cf04209
add `react-native-date-picker`
haileyok Mar 5, 2024
062a884
rm `@reactnativecommunity/datetimepicker`
haileyok Mar 5, 2024
b7c278e
migrate to `react-native-date-picker`
haileyok Mar 5, 2024
53a4008
use modal on android
haileyok Mar 5, 2024
4d5b6c3
fix android alf
haileyok Mar 5, 2024
c4995d3
Merge branch 'hailey/fabric-migration-pt2' into hailey/fabric-migrati…
haileyok Mar 5, 2024
f0bde40
Merge branch 'hailey/fabric-migration-pt3' into hailey/fabric-migrati…
haileyok Mar 5, 2024
86d321c
Merge branch 'hailey/fabric-migration-pt4' into hailey/fabric-migrati…
haileyok Mar 5, 2024
c96c8bd
Merge branch 'hailey/fabric-migration-pt5' into hailey/fabric-migrati…
haileyok Mar 5, 2024
1402b40
Merge branch 'hailey/fabric-migration-pt6' into hailey/fabric-migrati…
haileyok Mar 5, 2024
86c48e2
enable new arch on iOS
haileyok Mar 5, 2024
369ab09
enable new arch on iOS
haileyok Mar 5, 2024
9915076
Revert "enable new arch on iOS"
haileyok Mar 5, 2024
1fe0f10
enable new arch on iOS
haileyok Mar 5, 2024
3405ab8
enable new arch on android
haileyok Mar 5, 2024
6a46957
various upgrades
haileyok Mar 5, 2024
01d6253
adjust metro config
haileyok Mar 5, 2024
a57e6bb
more package upgrades (maybe, might revert)
haileyok Mar 5, 2024
73076b4
url hack fix
haileyok Mar 5, 2024
df1b8e1
get ios to a launchable state
haileyok Mar 5, 2024
78ecbb0
fix some border radius bugs
haileyok Mar 5, 2024
ca0d2e9
use @discord/bottom-sheet
haileyok Mar 5, 2024
5671590
use @discord/bottom-sheet
haileyok Mar 5, 2024
9531cfc
rm discord
haileyok Mar 5, 2024
568d75e
merge in discord
haileyok Mar 5, 2024
f27e26f
apply only necessary upgrades
haileyok Mar 5, 2024
ab66b9f
fix crashes
haileyok Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 94 additions & 51 deletions __tests__/lib/images.test.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
import {
downloadAndResize,
DownloadAndResizeOpts,
} from '../../src/lib/media/manip'
import ImageResizer from '@bam.tech/react-native-image-resizer'
import RNFetchBlob from 'rn-fetch-blob'
getResizedDimensions,
} from 'lib/media/manip'
import {manipulateAsync, SaveFormat} from 'expo-image-manipulator'
import {createDownloadResumable, deleteAsync} from 'expo-file-system'

describe('downloadAndResize', () => {
const errorSpy = jest.spyOn(global.console, 'error')

const mockResizedImage = {
path: jest.fn().mockReturnValue('file://resized-image.jpg'),
path: 'file://resized-image.jpg',
size: 100,
width: 50,
height: 50,
width: 100,
height: 100,
mime: 'image/jpeg',
}

beforeEach(() => {
const mockedCreateResizedImage =
ImageResizer.createResizedImage as jest.Mock
mockedCreateResizedImage.mockResolvedValue(mockResizedImage)
const mockedCreateResizedImage = manipulateAsync as jest.Mock
mockedCreateResizedImage.mockResolvedValue({
uri: 'file://resized-image.jpg',
...mockResizedImage,
})
})

afterEach(() => {
jest.clearAllMocks()
})

it('should return resized image for valid URI and options', async () => {
const mockedFetch = RNFetchBlob.fetch as jest.Mock
mockedFetch.mockResolvedValueOnce({
path: jest.fn().mockReturnValue('file://downloaded-image.jpg'),
flush: jest.fn(),
const mockedFetch = createDownloadResumable as jest.Mock
mockedFetch.mockReturnValue({
cancelAsync: jest.fn(),
downloadAsync: jest
.fn()
.mockResolvedValue({uri: 'file://resized-image.jpg'}),
})

const opts: DownloadAndResizeOpts = {
Expand All @@ -44,25 +49,22 @@ describe('downloadAndResize', () => {

const result = await downloadAndResize(opts)
expect(result).toEqual(mockResizedImage)
expect(RNFetchBlob.config).toHaveBeenCalledWith({
fileCache: true,
appendExt: 'jpeg',
})
expect(RNFetchBlob.fetch).toHaveBeenCalledWith(
'GET',
'https://example.com/image.jpg',
expect(createDownloadResumable).toHaveBeenCalledWith(
opts.uri,
expect.anything(),
{
cache: true,
},
)
expect(ImageResizer.createResizedImage).toHaveBeenCalledWith(
'file://downloaded-image.jpg',
100,
100,
'JPEG',
100,
undefined,
undefined,
undefined,
{mode: 'cover'},
expect(manipulateAsync).toHaveBeenCalledWith(expect.anything(), [], {
format: SaveFormat.JPEG,
})
expect(manipulateAsync).toHaveBeenCalledWith(
expect.anything(),
[{resize: {height: opts.height, width: opts.width}}],
{format: SaveFormat.JPEG, compress: 0.9},
)
expect(deleteAsync).toHaveBeenCalledWith(expect.anything())
})

it('should return undefined for invalid URI', async () => {
Expand All @@ -81,10 +83,12 @@ describe('downloadAndResize', () => {
})

it('should return undefined for unsupported file type', async () => {
const mockedFetch = RNFetchBlob.fetch as jest.Mock
mockedFetch.mockResolvedValueOnce({
path: jest.fn().mockReturnValue('file://downloaded-image'),
flush: jest.fn(),
const mockedFetch = createDownloadResumable as jest.Mock
mockedFetch.mockReturnValue({
cancelAsync: jest.fn(),
downloadAsync: jest
.fn()
.mockResolvedValue({uri: 'file://downloaded-image'}),
})

const opts: DownloadAndResizeOpts = {
Expand All @@ -98,24 +102,63 @@ describe('downloadAndResize', () => {

const result = await downloadAndResize(opts)
expect(result).toEqual(mockResizedImage)
expect(RNFetchBlob.config).toHaveBeenCalledWith({
fileCache: true,
appendExt: 'jpeg',
})
expect(RNFetchBlob.fetch).toHaveBeenCalledWith(
'GET',
'https://example.com/image',
expect(createDownloadResumable).toHaveBeenCalledWith(
opts.uri,
expect.anything(),
{
cache: true,
},
)
expect(ImageResizer.createResizedImage).toHaveBeenCalledWith(
'file://downloaded-image',
100,
100,
'JPEG',
100,
undefined,
undefined,
undefined,
{mode: 'cover'},
expect(manipulateAsync).toHaveBeenCalledWith(expect.anything(), [], {
format: SaveFormat.JPEG,
})
expect(manipulateAsync).toHaveBeenCalledWith(
expect.anything(),
[{resize: {height: opts.height, width: opts.width}}],
{format: SaveFormat.JPEG, compress: 0.9},
)
expect(deleteAsync).toHaveBeenCalledWith(expect.anything())
})
})

describe('produces correct new sizes for images', () => {
it('should not downsize whenever dimensions are below the max dimensions', () => {
const initialDimensionsOne = {
width: 1200,
height: 1000,
}
const resizedDimensionsOne = getResizedDimensions(initialDimensionsOne)

const initialDimensionsTwo = {
width: 1000,
height: 1200,
}
const resizedDimensionsTwo = getResizedDimensions(initialDimensionsTwo)

expect(resizedDimensionsOne).toEqual(initialDimensionsOne)
expect(resizedDimensionsTwo).toEqual(initialDimensionsTwo)
})

it('should resize dimensions and maintain aspect ratio if they are above the max dimensons', () => {
const initialDimensionsOne = {
width: 3000,
height: 1500,
}
const resizedDimensionsOne = getResizedDimensions(initialDimensionsOne)

const initialDimensionsTwo = {
width: 2000,
height: 4000,
}
const resizedDimensionsTwo = getResizedDimensions(initialDimensionsTwo)

expect(resizedDimensionsOne).toEqual({
width: 2000,
height: 1000,
})
expect(resizedDimensionsTwo).toEqual({
width: 1000,
height: 2000,
})
})
})
2 changes: 2 additions & 0 deletions app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ module.exports = function (config) {
{
ios: {
deploymentTarget: '13.4',
newArchEnabled: true,
},
android: {
compileSdkVersion: 34,
targetSdkVersion: 34,
buildToolsVersion: '34.0.0',
kotlinVersion: '1.8.0',
newArchEnabled: true,
},
},
],
Expand Down
17 changes: 11 additions & 6 deletions jest/jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ jest.mock('react-native-safe-area-context', () => {
}
})

jest.mock('rn-fetch-blob', () => ({
config: jest.fn().mockReturnThis(),
cancel: jest.fn(),
fetch: jest.fn(),
jest.mock('expo-file-system', () => ({
createDownloadResumable: jest.fn(),
deleteAsync: jest.fn(),
getInfoAsync: jest.fn().mockResolvedValue({
size: 100,
}),
}))

jest.mock('@bam.tech/react-native-image-resizer', () => ({
createResizedImage: jest.fn(),
jest.mock('expo-image-manipulator', () => ({
manipulateAsync: jest.fn().mockResolvedValue({
uri: 'file://resized-image',
}),
SaveFormat: jest.requireActual('expo-image-manipulator').SaveFormat,
}))

jest.mock('@segment/analytics-react-native', () => ({
Expand Down
9 changes: 0 additions & 9 deletions metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ cfg.transformer.getTransformOptions = async () => ({
transform: {
experimentalImportSupport: true,
inlineRequires: true,
nonInlinedRequires: [
// We can remove this option and rely on the default after
// https://github.com/facebook/metro/pull/1126 is released.
'React',
'react',
'react/jsx-dev-runtime',
'react/jsx-runtime',
'react-native',
],
},
})

Expand Down
Loading
Loading