You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Get the imageconstimagePicker=create({mode: 'single',mediaType: ImagePickerMediaType.Image,prompt: 'Select a photo',});awaitimagePicker.authorize();constselection=awaitimagePicker.present();constselectedImages=selection.map((selectedImage)=>selectedImage.asset);// Upload the imageconstloadingIndicator=newLoadingIndicator();loadingIndicator.show({message: 'Uploading photo...',});awaituploadPhoto(selectedImages[0]);loadingIndicator.hide();
You would expect the loading indicator to display right after the image is selected, but it never does. From what I can tell, this is because the loading indictor is displaying right away, but it displays in the context of the image picker modal which is in the process of closing. Thus, you never see it back in the view that presented the image picker.
Workaround
By using a setTimeout to wait for the modal to fully close, the loading indicator can display correctly:
...
constselection=awaitimagePicker.present();constselectedImages=selection.map((selectedImage)=>selectedImage.asset);setTimeout(async()=>{constloadingIndicator=newLoadingIndicator();loadingIndicator.show({message: 'Uploading photo...',});awaituploadPhoto(selectedImages[0]);loadingIndicator.hide();},250);// Wait for the iOS image picker to close.
Reproduction
Minimal example on StackBlitz
Notice that there is no loading indicator. Uncomment lines 23 and 37 in main-view-model.ts to re-enable the setTimeout. Re-run and notice that the loading indicator now displays correctly.
Expected Behavior
ImagePicker.present waits for the modal to be fully closed before resolving the Promise, thus avoiding this type of issue altogether.
The text was updated successfully, but these errors were encountered:
The Issue
Consider the following common use case:
I'm currently implementing this using
@nstudio/nativescript-loading-indicator
(v4.3.4) and @nativescript/imagepicker (v3.0.1):You would expect the loading indicator to display right after the image is selected, but it never does. From what I can tell, this is because the loading indictor is displaying right away, but it displays in the context of the image picker modal which is in the process of closing. Thus, you never see it back in the view that presented the image picker.
Workaround
By using a
setTimeout
to wait for the modal to fully close, the loading indicator can display correctly:Reproduction
Minimal example on StackBlitz
Notice that there is no loading indicator. Uncomment lines 23 and 37 in
main-view-model.ts
to re-enable thesetTimeout
. Re-run and notice that the loading indicator now displays correctly.Expected Behavior
ImagePicker.present
waits for the modal to be fully closed before resolving the Promise, thus avoiding this type of issue altogether.The text was updated successfully, but these errors were encountered: