Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e7ca379
feat: init local library
szymonrybczak Nov 20, 2024
82ce553
feat: add `defineTask` method
szymonrybczak Nov 20, 2024
4c96c52
feat: use BGTaskScheduler api
szymonrybczak Nov 20, 2024
f181955
fix: remove useless condition
szymonrybczak Nov 26, 2024
cc214f8
feat: properly register & add basic handler
szymonrybczak Nov 27, 2024
4a55c9b
feat: execute js function from native
szymonrybczak Nov 27, 2024
ec9680c
chore: clean up usage on JS side
szymonrybczak Nov 27, 2024
8da06e2
fix: replace `BGProcessingTaskRequest` with `BGProcessingTaskRequest`
szymonrybczak Nov 27, 2024
6a06a97
chore: small code cleaning
szymonrybczak Dec 3, 2024
aefe68e
fix: remove android related stuff for now
szymonrybczak Dec 4, 2024
2f6dc68
fix: replace hardcoded identifier
szymonrybczak Dec 9, 2024
d4d6a31
chore: code cleanup
szymonrybczak Dec 9, 2024
5de130d
chore: one line impl in `AppDelegate.mm`
szymonrybczak Dec 9, 2024
138ad72
chore: remove header comments
szymonrybczak Dec 9, 2024
5d2abd1
feat: implement sequential task scheduling
szymonrybczak Dec 9, 2024
3a2b3c9
chore: remove useless observer
szymonrybczak Dec 9, 2024
82c42ac
fix: properly order packages in `package.json`
szymonrybczak Dec 10, 2024
532a007
feat!: use new EventEmitter API
szymonrybczak Dec 10, 2024
99bf557
fix: make 0 warnings
szymonrybczak Dec 10, 2024
94769ea
fix: add proper bundle id
szymonrybczak Dec 10, 2024
a9d5755
fix: add release bundle id
szymonrybczak Dec 10, 2024
e663e60
fix: include all bundle identifiers
szymonrybczak Dec 11, 2024
1b252dd
fix: replace `BGProcessingTaskRequest` with `BGAppRefreshTaskRequest`
szymonrybczak Dec 17, 2024
34813d6
fix: call `resolve()` only once when there's multiple identifiers
szymonrybczak Dec 17, 2024
0e504da
fix: use bg task specific id
szymonrybczak Dec 20, 2024
a062fc9
fix: remove oudated condition in `Podfile`
szymonrybczak Dec 30, 2024
49632c5
chore: update lock
szymonrybczak Jan 7, 2025
a8884a0
fix: eslint warnings
szymonrybczak Jan 7, 2025
74d6767
fix: mock module
szymonrybczak Jan 8, 2025
310e010
feat: add a log when executing background task
szymonrybczak Jan 8, 2025
a1c707e
fix: move mocks to one file
szymonrybczak Jan 13, 2025
8a914f3
feat: pass error to JS
szymonrybczak Jan 13, 2025
6276845
fix: eslint error
szymonrybczak Jan 14, 2025
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
4 changes: 4 additions & 0 deletions ios/NewExpensify.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
7FD73CA22B23CE9500420AF3 /* NotificationServiceExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 7FD73C9B2B23CE9500420AF3 /* NotificationServiceExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
8744C5400E24E379441C04A4 /* libPods-NewExpensify.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 59A21B2405370FDDD847C813 /* libPods-NewExpensify.a */; };
9E17CB36A6B22BDD4BE53561 /* libPods-NotificationServiceExtension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9196A72C11B91A52A43D6E8A /* libPods-NotificationServiceExtension.a */; };
AC131FBB2CF634F20010CE80 /* BackgroundTasks.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AC131FBA2CF634F20010CE80 /* BackgroundTasks.framework */; };
ACA597C323AA39404655647F /* libPods-NewExpensify-NewExpensifyTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EF33B19FC6A7FE676839430D /* libPods-NewExpensify-NewExpensifyTests.a */; };
BDB853621F354EBB84E619C2 /* ExpensifyNewKansas-MediumItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = D2AFB39EC1D44BF9B91D3227 /* ExpensifyNewKansas-MediumItalic.otf */; };
D27CE6B77196EF3EF450EEAC /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 0D3F9E814828D91464DF9D35 /* PrivacyInfo.xcprivacy */; };
Expand Down Expand Up @@ -141,6 +142,7 @@
8B28D84EF339436DBD42A203 /* ExpensifyNeue-BoldItalic.otf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "ExpensifyNeue-BoldItalic.otf"; path = "../assets/fonts/native/ExpensifyNeue-BoldItalic.otf"; sourceTree = "<group>"; };
8EFE0319D586C1078DB926FD /* Pods-NewExpensify.releaseadhoc.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NewExpensify.releaseadhoc.xcconfig"; path = "Target Support Files/Pods-NewExpensify/Pods-NewExpensify.releaseadhoc.xcconfig"; sourceTree = "<group>"; };
9196A72C11B91A52A43D6E8A /* libPods-NotificationServiceExtension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-NotificationServiceExtension.a"; sourceTree = BUILT_PRODUCTS_DIR; };
AC131FBA2CF634F20010CE80 /* BackgroundTasks.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = BackgroundTasks.framework; path = System/Library/Frameworks/BackgroundTasks.framework; sourceTree = SDKROOT; };
BBE493797E97F2995E627244 /* Pods-NotificationServiceExtension.debugadhoc.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationServiceExtension.debugadhoc.xcconfig"; path = "Target Support Files/Pods-NotificationServiceExtension/Pods-NotificationServiceExtension.debugadhoc.xcconfig"; sourceTree = "<group>"; };
BCD444BEDDB0AF1745B39049 /* ExpoModulesProvider.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ExpoModulesProvider.swift; path = "Pods/Target Support Files/Pods-NewExpensify-NewExpensifyTests/ExpoModulesProvider.swift"; sourceTree = "<group>"; };
BF6A4C5167244B9FB8E4D4E3 /* ExpensifyNeue-Italic.otf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "ExpensifyNeue-Italic.otf"; path = "../assets/fonts/native/ExpensifyNeue-Italic.otf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -180,6 +182,7 @@
383643682B6D4AE2005BB9AE /* DeviceCheck.framework in Frameworks */,
E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */,
E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */,
AC131FBB2CF634F20010CE80 /* BackgroundTasks.framework in Frameworks */,
8744C5400E24E379441C04A4 /* libPods-NewExpensify.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -239,6 +242,7 @@
2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
isa = PBXGroup;
children = (
AC131FBA2CF634F20010CE80 /* BackgroundTasks.framework */,
383643672B6D4AE2005BB9AE /* DeviceCheck.framework */,
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
ED2971642150620600B7C4FE /* JavaScriptCore.framework */,
Expand Down
4 changes: 4 additions & 0 deletions ios/NewExpensify/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "RCTBootSplash.h"
#import "RCTStartupTimer.h"
#import <HardwareShortcuts.h>
#import <BackgroundTasks/BackgroundTasks.h>
#import <expensify-react-native-background-task/RNBackgroundTaskManager.h>

@interface AppDelegate () <UNUserNotificationCenterDelegate>

Expand Down Expand Up @@ -49,6 +51,8 @@ - (BOOL)application:(UIApplication *)application
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isFirstRunComplete"];
}

[RNBackgroundTaskManager setup];

return YES;
}
Expand Down
6 changes: 6 additions & 0 deletions ios/NewExpensify/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.chat.expensify.backgroundTaskSync</string>
</array>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
Expand Down Expand Up @@ -97,6 +101,8 @@
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
<string>fetch</string>
<string>processing</string>
</array>
<key>UIFileSharingEnabled</key>
<true/>
Expand Down
25 changes: 25 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ PODS:
- EXImageLoader (5.0.0):
- ExpoModulesCore
- React-Core
- expensify-react-native-background-task (0.0.0):
- 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
- Expo (52.0.14):
- ExpoModulesCore
- ExpoAsset (11.0.1):
Expand Down Expand Up @@ -2813,6 +2834,7 @@ DEPENDENCIES:
- DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
- EXAV (from `../node_modules/expo-av/ios`)
- EXImageLoader (from `../node_modules/expo-image-loader/ios`)
- "expensify-react-native-background-task (from `../node_modules/@expensify/react-native-background-task`)"
- Expo (from `../node_modules/expo`)
- ExpoAsset (from `../node_modules/expo-asset/ios`)
- ExpoFont (from `../node_modules/expo-font/ios`)
Expand Down Expand Up @@ -2982,6 +3004,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/expo-av/ios"
EXImageLoader:
:path: "../node_modules/expo-image-loader/ios"
expensify-react-native-background-task:
:path: "../node_modules/@expensify/react-native-background-task"
Expo:
:path: "../node_modules/expo"
ExpoAsset:
Expand Down Expand Up @@ -3228,6 +3252,7 @@ SPEC CHECKSUMS:
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
EXAV: 9773c9799767c9925547b05e41a26a0240bb8ef2
EXImageLoader: 759063a65ab016b836f73972d3bb25404888713d
expensify-react-native-background-task: 6f797cf470b627912c246514b1631a205794775d
Expo: 0e7b52be71a24a38d5e919e3040d8f51a8739cd0
ExpoAsset: 8138f2a9ec55ae1ad7c3871448379f7d97692d15
ExpoFont: 7522d869d84ee2ee8093ee997fef5b86f85d856b
Expand Down
12 changes: 12 additions & 0 deletions ios/tmp.xcconfig

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szymonrybczak any reason we committed this file to the repo? Normally it's just a temporary file used in production builds.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a look at this, probably remove it and add it into the .gitignore, thanks for caching this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on this in this PR: #56169

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks but I already got to it in this PR: #57058

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
NEW_EXPENSIFY_URL=https:/$()/new.expensify.com/
SECURE_EXPENSIFY_URL=https:/$()/secure.expensify.com/
EXPENSIFY_URL=https:/$()/www.expensify.com/
EXPENSIFY_PARTNER_NAME=chat-expensify-com
EXPENSIFY_PARTNER_PASSWORD=e21965746fd75f82bb66
PUSHER_APP_KEY=268df511a204fbb60884
USE_WEB_PROXY=false
ENVIRONMENT=production
SEND_CRASH_REPORTS=true
FB_API_KEY=AIzaSyBrLKgCuo6Vem6Xi5RPokdumssW8HaWBow
FB_APP_ID=1:1008697809946:web:08de4ecb7656b7235445a3
FB_PROJECT_ID=expensify-mobile-app
5 changes: 5 additions & 0 deletions jest/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ jest.mock('@src/libs/actions/Timing', () => ({
end: jest.fn(),
}));

jest.mock('../modules/background-task/src/NativeReactNativeBackgroundTask', () => ({
defineTask: jest.fn(),
onBackgroundTaskExecution: jest.fn(),
}));

// This makes FlatList render synchronously for easier testing.
jest.mock(
'@react-native/virtualized-lists/Interaction/Batchinator',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

Pod::Spec.new do |s|
s.name = "expensify-react-native-background-task"
s.version = package["version"]
s.summary = package["description"]
s.homepage = package["homepage"]
s.license = package["license"]
s.authors = package["author"]

s.platforms = { :ios => min_ios_version_supported }
s.source = { :git => ".git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm,cpp}"

install_modules_dependencies(s)
end
15 changes: 15 additions & 0 deletions modules/background-task/ios/RNBackgroundTaskManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#import <Foundation/Foundation.h>
#import <BackgroundTasks/BackgroundTasks.h>
#import <React/RCTBridgeModule.h>

@interface RNBackgroundTaskManager : NSObject

@property (nonatomic, copy) void (^ _Nullable taskHandler)(BGTask * _Nonnull);

+ (instancetype _Nullable )shared;
+ (void)setup;
- (void)setHandlerForIdentifier:(NSString *_Nullable)identifier
completion:(void (^_Nullable)(BGTask * _Nonnull))handler;
- (void (^_Nullable)(BGTask * _Nonnull))handlerForIdentifier:(NSString *_Nullable)identifier;

@end
52 changes: 52 additions & 0 deletions modules/background-task/ios/RNBackgroundTaskManager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#import <BackgroundTasks/BackgroundTasks.h>

@implementation RNBackgroundTaskManager : NSObject {
NSMutableDictionary<NSString *, void (^)(BGTask * _Nonnull)> *_handlers;
}

+ (instancetype)shared {
static RNBackgroundTaskManager *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[RNBackgroundTaskManager alloc] init];
});
return instance;
}

- (instancetype)init {
if (self = [super init]) {
_handlers = [NSMutableDictionary new];
}
return self;
}

- (void)setHandlerForIdentifier:(NSString *)identifier
completion:(void (^)(BGTask * _Nonnull))handler {
_handlers[identifier] = handler;
}

- (void (^)(BGTask * _Nonnull))handlerForIdentifier:(NSString *)identifier {
return _handlers[identifier];
}

+ (void)setup {
NSArray *backgroundIdentifiers = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"BGTaskSchedulerPermittedIdentifiers"];

if (!backgroundIdentifiers || ![backgroundIdentifiers isKindOfClass:[NSArray class]]) {
NSLog(@"[ReactNativeBackgroundTask] No background identifiers found or invalid format");
} else {
for (NSString *identifier in backgroundIdentifiers) {
[[BGTaskScheduler sharedScheduler] registerForTaskWithIdentifier:identifier
usingQueue:nil
launchHandler:^(BGTask * _Nonnull task) {
NSLog(@"[ReactNativeBackgroundTask] Executing background task: %@", task.identifier);
void (^handler)(BGTask * _Nonnull) = [[RNBackgroundTaskManager shared] handlerForIdentifier:task.identifier];
if (handler) {
handler(task);
}
}];
}
}
}

@end
18 changes: 18 additions & 0 deletions modules/background-task/ios/ReactNativeBackgroundTask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifdef RCT_NEW_ARCH_ENABLED
#import "RNReactNativeBackgroundTaskSpec.h"
#import <BackgroundTasks/BackgroundTasks.h>

@interface ReactNativeBackgroundTask : NativeReactNativeBackgroundTaskSpecBase <NativeReactNativeBackgroundTaskSpec>
#else
#import <React/RCTBridgeModule.h>
#import <BackgroundTasks/BackgroundTasks.h>

@interface ReactNativeBackgroundTask : NSObject <RCTBridgeModule>
#endif

- (void)defineTask:(NSString *)taskName
taskExecutor:(RCTResponseSenderBlock)taskExecutor
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject;

@end
117 changes: 117 additions & 0 deletions modules/background-task/ios/ReactNativeBackgroundTask.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#import "ReactNativeBackgroundTask.h"
#import <UIKit/UIKit.h>
#import <BackgroundTasks/BackgroundTasks.h>
#import "RNBackgroundTaskManager.h"

@implementation ReactNativeBackgroundTask {
NSMutableDictionary *_taskExecutors;
}

RCT_EXPORT_MODULE()

- (instancetype)init {
if (self = [super init]) {
_taskExecutors = [NSMutableDictionary new];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we need any kind of concurrency safety for _taskExecutors?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think concurrency protection needed for _taskExecutors because:

  • defineTask (RCT_EXPORT_METHOD) runs on main thread
  • BGTask handlers run on main thread

These are the only two places accessing _taskExecutors. Adding synchronization would just add overhead with no benefit since everything already runs on the main thread.

}
return self;
}

- (BOOL)scheduleNewBackgroundTask:(NSString *)identifier error:(NSError **)outError {
BGAppRefreshTaskRequest *request = [[BGAppRefreshTaskRequest alloc] initWithIdentifier:identifier];

// Set earliest begin date to some time in the future
request.earliestBeginDate = [NSDate dateWithTimeIntervalSinceNow:15 * 60]; // 15 minutes from now

NSError *error = nil;
BOOL success = [[BGTaskScheduler sharedScheduler] submitTaskRequest:request error:&error];

if (!success) {
NSLog(@"[ReactNativeBackgroundTask] Failed to schedule task: %@", error.localizedDescription);
if (outError != nil) {
*outError = error;
}
}

return success;
}

RCT_EXPORT_METHOD(defineTask:(NSString *)taskName
taskExecutor:(RCTResponseSenderBlock)taskExecutor
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
{
if (taskName == nil) {
NSLog(@"[ReactNativeBackgroundTask] Failed to define task: taskName is nil");
reject(@"ERR_INVALID_TASK_NAME", @"Task name must be provided", nil);
return;
}

if (taskExecutor == nil) {
NSLog(@"[ReactNativeBackgroundTask] Failed to define task: taskExecutor is nil");
reject(@"ERR_INVALID_TASK_EXECUTOR", @"Task executor must be provided", nil);
return;
}

NSArray *backgroundIdentifiers = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"BGTaskSchedulerPermittedIdentifiers"];


if (!backgroundIdentifiers || ![backgroundIdentifiers isKindOfClass:[NSArray class]]) {
NSLog(@"[ReactNativeBackgroundTask] No background identifiers found or invalid format");
reject(@"ERR_INVALID_TASK_SCHEDULER_IDENTIFIER", @"No background identifiers found or invalid format", nil);
return;
}

NSLog(@"[ReactNativeBackgroundTask] Defining task: %@", taskName);

BOOL allSuccess = YES;
NSError *taskError = nil;

for (NSString *identifier in backgroundIdentifiers) {
[[RNBackgroundTaskManager shared] setHandlerForIdentifier:identifier completion:^(BGTask * _Nonnull task) {
NSLog(@"[ReactNativeBackgroundTask] Executing background task's handler");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my previous experiences with background handling, we had some sort of expiry handling/time out logic. do you think we need it here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a way for force finishing background task programmatically but for our use case I don't think that's necessary.


// Execute all registered tasks
[self->_taskExecutors enumerateKeysAndObjectsUsingBlock:^(NSString *taskName, RCTResponseSenderBlock executor, BOOL *stop) {
NSLog(@"[ReactNativeBackgroundTask] Executing task: %@", taskName);
[self emitOnBackgroundTaskExecution:(taskName)];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question where is this method coming from? I couldn't quickly find in the Apple docs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emitOnBackgroundTaskExecution is created by React Native Codegen when the type of a function is marked with EventEmitter. This is a new way of emitting events in React Native added in 0.76 - here are related docs: https://github.com/reactwg/react-native-new-architecture/blob/main/docs/turbo-modules.md#add-event-emitting-capabilities

}];

NSError *scheduleError = nil;
[self scheduleNewBackgroundTask:identifier error:&scheduleError];

[task setTaskCompletedWithSuccess:YES];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a lot of context, but should this be inside the loop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why in loop? When the execution of one task finish we schedule another execution for the same task

}];

NSError *scheduleError = nil;
BOOL success = [self scheduleNewBackgroundTask:identifier error:&scheduleError];

if (success) {
_taskExecutors[taskName] = taskExecutor;
} else {
allSuccess = NO;
taskError = scheduleError;
break;
}
}

if (allSuccess) {
resolve(@YES);
} else {
reject(@"ERR_SCHEDULE_TASK_FAILED",
taskError.localizedDescription ?: @"Failed to schedule initial background task",
taskError);
}

_taskExecutors[taskName] = taskExecutor;
}

// Don't compile this code when we build for the old architecture.
#ifdef RCT_NEW_ARCH_ENABLED
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::NativeReactNativeBackgroundTaskSpecJSI>(params);
}
#endif

@end
19 changes: 19 additions & 0 deletions modules/background-task/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@expensify/react-native-background-task",
"version": "0.0.0",
"description": "Execute tasks in background",
"main": "src/index",
"codegenConfig": {
"name": "RNReactNativeBackgroundTaskSpec",
"type": "modules",
"jsSrcsDir": "src"
},
"author": " <> ()",
"license": "UNLICENSED",
"homepage": "#readme",
"create-react-native-library": {
"type": "module-mixed",
"languages": "kotlin-objc",
"version": "0.44.1"
}
}
Loading