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

[Feat] add background download option for ios and RN Upgrade #127

Merged
merged 6 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
feat: add background download for ios and replace react-native-fs wit…
…h @dr.pogodin/react-native-fs
  • Loading branch information
a-ghorbani committed Dec 3, 2024
commit 87dcf84bc711e3616991017479bb704358c20192
43 changes: 43 additions & 0 deletions __mocks__/external/@dr.pogodin/react-native-fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export const mkdir = jest.fn();
export const unlink = jest.fn();
export const exists = jest.fn();
export const stopDownload = jest.fn();
export const readFile = jest.fn(path => {
if (path.includes('session-metadata.json')) {
// Return valid session metadata JSON
return Promise.resolve(
JSON.stringify([
{
id: '1',
title: 'Test Session',
date: '2024-01-01T00:00:00Z',
messages: [],
},
]),
);
}

// Handle other required file.
return Promise.resolve('Some default content');
});
export const writeFile = jest.fn((path, data) => {
return Promise.resolve();
});
export const downloadFile = jest.fn();
export const DocumentDirectoryPath = '/path/to/documents';
export const copyFile = jest.fn().mockResolvedValue(true);

// Add namespace export for compatibility
const RNFS = {
mkdir,
unlink,
exists,
stopDownload,
readFile,
writeFile,
downloadFile,
DocumentDirectoryPath,
copyFile,
};

export {RNFS};
30 changes: 0 additions & 30 deletions __mocks__/external/react-native-fs.js

This file was deleted.

6 changes: 3 additions & 3 deletions ios/PocketPal/AppDelegate.mm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <RNFSManager.h>
#import <RNFSBackgroundDownloads.h>

@implementation AppDelegate

Expand Down Expand Up @@ -29,9 +29,9 @@ - (NSURL *)bundleURL
#endif
}

- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler
{
[RNFSManager setCompletionHandlerForIdentifier:identifier completionHandler:completionHandler];
[RNFSBackgroundDownloads setCompletionHandlerForIdentifier:identifier completionHandler:completionHandler];
}

@end
37 changes: 25 additions & 12 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ PODS:
- BVLinearGradient (2.8.3):
- React-Core
- DoubleConversion (1.1.6)
- dr-pogodin-react-native-fs (2.30.1):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- FBLazyVector (0.76.3)
- fmt (9.1.0)
- glog (0.3.5)
Expand Down Expand Up @@ -1246,8 +1267,6 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-blob-util (0.19.11):
- React-Core
- react-native-blur (4.4.1):
- DoubleConversion
- glog
Expand Down Expand Up @@ -1598,8 +1617,6 @@ PODS:
- React-Core
- RNDeviceInfo (13.1.0):
- React-Core
- RNFS (2.20.0):
- React-Core
- RNGestureHandler (2.20.2):
- DoubleConversion
- glog
Expand Down Expand Up @@ -1760,6 +1777,7 @@ DEPENDENCIES:
- boost (from `../node_modules/react-native/third-party-podspecs/boost.podspec`)
- BVLinearGradient (from `../node_modules/react-native-linear-gradient`)
- DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
- "dr-pogodin-react-native-fs (from `../node_modules/@dr.pogodin/react-native-fs`)"
- FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`)
- fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`)
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
Expand Down Expand Up @@ -1796,7 +1814,6 @@ DEPENDENCIES:
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
- React-microtasksnativemodule (from `../node_modules/react-native/ReactCommon/react/nativemodule/microtasks`)
- react-native-blob-util (from `../node_modules/react-native-blob-util`)
- "react-native-blur (from `../node_modules/@react-native-community/blur`)"
- react-native-config (from `../node_modules/react-native-config`)
- react-native-document-picker (from `../node_modules/react-native-document-picker`)
Expand Down Expand Up @@ -1836,7 +1853,6 @@ DEPENDENCIES:
- "RNCMaskedView (from `../node_modules/@react-native-masked-view/masked-view`)"
- "RNCPicker (from `../node_modules/@react-native-picker/picker`)"
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
- RNFS (from `../node_modules/react-native-fs`)
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
- RNReanimated (from `../node_modules/react-native-reanimated`)
- RNScreens (from `../node_modules/react-native-screens`)
Expand All @@ -1855,6 +1871,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-linear-gradient"
DoubleConversion:
:podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec"
dr-pogodin-react-native-fs:
:path: "../node_modules/@dr.pogodin/react-native-fs"
FBLazyVector:
:path: "../node_modules/react-native/Libraries/FBLazyVector"
fmt:
Expand Down Expand Up @@ -1924,8 +1942,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon"
React-microtasksnativemodule:
:path: "../node_modules/react-native/ReactCommon/react/nativemodule/microtasks"
react-native-blob-util:
:path: "../node_modules/react-native-blob-util"
react-native-blur:
:path: "../node_modules/@react-native-community/blur"
react-native-config:
Expand Down Expand Up @@ -2004,8 +2020,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-picker/picker"
RNDeviceInfo:
:path: "../node_modules/react-native-device-info"
RNFS:
:path: "../node_modules/react-native-fs"
RNGestureHandler:
:path: "../node_modules/react-native-gesture-handler"
RNReanimated:
Expand All @@ -2023,6 +2037,7 @@ SPEC CHECKSUMS:
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
BVLinearGradient: cb006ba232a1f3e4f341bb62c42d1098c284da70
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
dr-pogodin-react-native-fs: 6c198fc213e6a8d6679885d4df5868feed77db78
FBLazyVector: be7314029d6ec6b90f0f75ce1195b8130ed9ac4f
fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be
glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a
Expand Down Expand Up @@ -2057,7 +2072,6 @@ SPEC CHECKSUMS:
React-logger: 2736a90a3fdaed3dab1e2e9c5a5e9b3be00c287d
React-Mapbuffer: bd6a2ffbf401f11cfc8b5e8f38acab9fe117620c
React-microtasksnativemodule: e3e161b03573a22cf4e05434fe5309c7847ef197
react-native-blob-util: f7234c91ad0e3faeee51b3edee80b61553f74993
react-native-blur: 3d5dd1ed2dd810b304ac3bcee9cf7d460757c89b
react-native-config: ea75335a7cca1d3326de1da384227e580a7c082e
react-native-document-picker: 530879d9e89b490f0954bcc4ab697c5b5e35d659
Expand Down Expand Up @@ -2097,7 +2111,6 @@ SPEC CHECKSUMS:
RNCMaskedView: de80352547bd4f0d607bf6bab363d826822bd126
RNCPicker: d8662eb6615e3401acb590c44b97b2af3beb1e53
RNDeviceInfo: 014029374ada3164b6c40fe74041dca2f98b42d6
RNFS: 89de7d7f4c0f6bafa05343c578f61118c8282ed8
RNGestureHandler: 27a63f2218affdf1a426d56682f9b174904838b3
RNReanimated: 929c26a706dfe1af8feee9f2cf78004394e4dd04
RNScreens: e21c8d32fe97737ecc30f1f21e7b6f69f341a1f5
Expand Down
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
'<rootDir>/__mocks__/external/react-native-device-info.js',
'react-native-document-picker':
'<rootDir>/__mocks__/external/react-native-document-picker.js',
'react-native-fs': '<rootDir>/__mocks__/external/react-native-fs.js',
'@dr.pogodin/react-native-fs':
'<rootDir>/__mocks__/external/@dr.pogodin/react-native-fs.js',
},
};
27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"test": "jest"
},
"dependencies": {
"@dr.pogodin/react-native-fs": "^2.30.1",
"@flyerhq/react-native-link-preview": "^1.6.0",
"@gorhom/bottom-sheet": "^5.0.5",
"@pocketpalai/llama.rn": "0.4.3-1",
Expand All @@ -45,11 +46,9 @@
"mobx-react": "^9.1.1",
"react": "18.3.1",
"react-native": "0.76.3",
"react-native-blob-util": "^0.19.9",
"react-native-config": "^1.5.1",
"react-native-device-info": "^13.1.0",
"react-native-document-picker": "^9.1.2",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^2.20.2",
"react-native-get-random-values": "^1.11.0",
"react-native-image-viewing": "^0.2.2",
Expand All @@ -68,29 +67,29 @@
"uuid": "^10.0.0"
},
"devDependencies": {
"@babel/core": "^7.25.7",
"@babel/plugin-proposal-decorators": "^7.24.6",
"@babel/preset-env": "^7.25.7",
"@babel/core": "^7.25.2",
"@babel/plugin-proposal-decorators": "^7.25.9",
"@babel/preset-env": "^7.25.3",
"@babel/runtime": "^7.25.0",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@commitlint/cli": "^19.6.0",
"@commitlint/config-conventional": "^19.6.0",
"@react-native-community/cli": "15.0.1",
"@react-native-community/cli-platform-android": "15.0.1",
"@react-native-community/cli-platform-ios": "15.0.1",
"@react-native/babel-preset": "^0.76.3",
"@react-native/eslint-config": "0.76.3",
"@react-native/babel-preset": "0.76.3",
"@react-native/eslint-config": "0.73.2",
"@react-native/metro-config": "0.76.3",
"@react-native/typescript-config": "0.76.3",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/react-native": "^12.5.0",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.5",
"@testing-library/react-native": "^12.9.0",
"@types/jest": "^29.5.14",
"@types/lodash": "^4.17.13",
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"@types/uuid": "^10.0.0",
"babel-jest": "^29.7.0",
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"husky": "^9.1.6",
"husky": "^9.1.7",
"jest": "^29.6.3",
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Bubble/Bubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const Bubble = ({
}
};

const Container: React.ComponentClass<any> = false //copyable
const Container = false //copyable
? TouchableOpacity
: View;
return (
Expand Down
2 changes: 1 addition & 1 deletion src/screens/ModelsScreen/ModelsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

import {toJS} from 'mobx';
import {v4 as uuidv4} from 'uuid';
import RNFS from 'react-native-fs';
import * as RNFS from '@dr.pogodin/react-native-fs';
import 'react-native-get-random-values';
import {observer} from 'mobx-react-lite';
import DocumentPicker from 'react-native-document-picker';
Expand Down
2 changes: 1 addition & 1 deletion src/screens/ModelsScreen/__tests__/ModelsScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import {Alert} from 'react-native';

import RNFS from 'react-native-fs';
import * as RNFS from '@dr.pogodin/react-native-fs';
import DocumentPicker from 'react-native-document-picker';
import {fireEvent, render, waitFor, act} from '../../../../jest/test-utils';

Expand Down
45 changes: 37 additions & 8 deletions src/screens/SettingsScreen/SettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TouchableWithoutFeedback,
Keyboard,
TextInput,
ScrollView,
} from 'react-native';

import {debounce} from 'lodash';
Expand Down Expand Up @@ -70,11 +71,11 @@ export const SettingsScreen: React.FC = observer(() => {
};

return (
<TouchableWithoutFeedback onPress={handleOutsidePress}>
<SafeAreaView
style={[styles.safeArea, {backgroundColor: colors.surface}]}
edges={['bottom']}>
<View style={styles.container}>
<SafeAreaView
style={[styles.safeArea, {backgroundColor: colors.surface}]}
edges={['bottom']}>
<TouchableWithoutFeedback onPress={handleOutsidePress}>
<ScrollView contentContainerStyle={styles.container}>
{/* Model Settings Section */}
<Card style={styles.card}>
<Card.Title title={l10n.modelSettingsTitle} />
Expand Down Expand Up @@ -201,6 +202,34 @@ export const SettingsScreen: React.FC = observer(() => {
color={colors.primary}
/>
</View>

{Platform.OS === 'ios' && (
<View style={styles.settingItemContainer}>
<View style={styles.switchContainer}>
<View style={styles.textContainer}>
<Text variant="titleMedium" style={styles.textLabel}>
{l10n.iOSBackgroundDownload}
</Text>
<Text
variant="labelSmall"
style={[
styles.textDescription,
{color: colors.outline},
]}>
{l10n.iOSBackgroundDownloadDescription}
</Text>
</View>
<Switch
testID="ios-background-download-switch"
value={uiStore.iOSBackgroundDownloading}
onValueChange={value =>
uiStore.setiOSBackgroundDownloading(value)
}
color={colors.primary}
/>
</View>
</View>
)}
</Card.Content>
</Card>

Expand Down Expand Up @@ -256,8 +285,8 @@ export const SettingsScreen: React.FC = observer(() => {
</View>
</Card.Content>
</Card>
</View>
</SafeAreaView>
</TouchableWithoutFeedback>
</ScrollView>
</TouchableWithoutFeedback>
</SafeAreaView>
);
});
Loading
Loading