I have integrated realm flexible sync which download lots of data from realm database after user login and works fine but i want to show progress screen until all data are downloaded on first launch.
As per documentation i have integrated to get progress notification but it only notify when 100% downloaded which is not wise for our app as we want to show actual progress and once download complete start using the app.
Please find below code that i implemented for same as per documentation.
enum ProgressDirection {
Download = 'download',
Upload = 'upload',
}
enum ProgressMode {
ReportIndefinitely = 'reportIndefinitely',
ForCurrentlyOutstandingWork = 'forCurrentlyOutstandingWork',
}
const AppSync = () => {
const app = useApp();
const realm = useRealm();
useEffect(() => {
if (__DEV__) {
Realm.App.Sync.setLogLevel(app, 'debug');
}
const progressNotificationCallback = (transferred, transferable) => {
// Convert decimal to percent with no decimals
// (e.g. 0.6666... -> 67)
const percentTransferred = parseFloat((transferred / transferable).toFixed(2)) * 100;
console.log('percentTransferred', percentTransferred);
};
// Listen for changes to connection state
realm.syncSession?.addProgressNotification(
ProgressDirection.Download,
ProgressMode.ForCurrentlyOutstandingWork,
progressNotificationCallback
);
// Remove the connection listener when component unmounts
return () => {
realm.syncSession?.removeProgressNotification(progressNotificationCallback);
if (!realm.isClosed) realm.close();
};
}, []);
...
}
percentTransferred log showed only when percentTransferred to 100%
My aim is to have progress screen until data get downloaded and once downloaded then render the app part only after it.