I've been working on React Native app with Redux state management. In this app, Syncing happens every 1 minute. I hit 10 API calls each and every time. Recently I've noticed app freezes in the Android app on the following conditions altogether. 1. When connected to mobile data. 2. When coming from the background. 3. And when sync API hits.
When these 3 scenarios happen all together, the app freezes for some seconds.
function* syncAPICalls(action, sample = undefined) {
let sampleData = settings;
try {
yield* makeDevicesCall({});
yield* makeDashboardNotificationCall({});
if (isValidElement(sampleData)) {
sampleData = sample;
} else {
sampleData = yield call(sampleApiCall1);
}
yield* sampleFunc1({ param: param});
yield* sampleFunc2({ param: param});
yield* sampleFunc3({ param: param});
yield* sampleFunc4({ param: param});
yield* sampleFunc5({ param: param});
yield* sampleFunc6({ param: param});
let phoneNo;
if (isValidElement(phone)) {
phoneNo = phone;
} else {
let sampleData2 = yield call(sampleApiCall2);
phoneNo = sampleData2.contact_no;
}
yield* sampleFunc7({ param: param});
yield* sampleFunc8({ param: param});
} catch (e) {
if (__DEV__) {
console.log(e);
}
}
}
I've renamed everything like a sample. Each sampleFunction
will update the reducer using put
method.
When I removed the Sync operations, the app works smoother and when in the foreground also sync is smoother.
Only when coming from background, mobile data, sync freezes.
I can assure you that sync is calling only once. And all API is getting success response.
Verison
react-native-cli: 2.0.1
react-native: 0.59.9
Am I doing something wrong?. Kindly give me some ideas of what went wrong, Thanks.