Hide image while loading new source - react-native

I've implemented a React Native component which shows an image loaded from a remote server. The user can swipe the image out of the screen in order to navigate to the next image which is again loaded from the remote server. While loading of the second image, the old image is still visible on the screen.
I want the old image to disappear while loading the next image. Any hint how to achieve this?
Prop defaultSource only works for initial render (showing the first image) but not consecutive images. So I guess React reuses the Image under the hood. I've played around with onLoadStart and onLoadEnd but I don't know how to reset the source of the old image.
Any idea?
Thanks.

Add a unique key prop to each image. It can be a number or a string. That will prevent React from re-using the elements.

Related

React navigation: manually change screen with swipe up effect

I have a screen with WebView (react-native-webview) which has scrollable content. If user continues scrolling after reaching the end of WebView, I want to take user to a different screen with a swipe up animation. With WebView's onScroll function property, I am able to determine if the user has reached end of content or not. But I am not able to take user to a different screen with an animation effect.
Since WebView acts different for android and ios platform (you can continue scrolling even after reaching end of content on ios), I had to use PanGestureHandler to identify if the user is performing swipe up action after reaching end of web content. But when I manually try to navigate user to a different screen, I am unable to create swipe up effect similar to one in GIF below.
I am using react-navigation v5 in my app.
I have already tried using react-native-swiper. It does not work well in Android because it internally uses Scrollable and WebView stop scrolling inside a Scrollable component.
I am using custom HTML content here, so replacing WebView is not really a choice. Is there a way to utilize Stack Navigator to create such an effect?
Thank you.

How to detect map container resize due to slow loading image?

I am creating an app with a Leaflet map in Nuxt using Vue2Leaflet plugin.
I am having a problem though: I am using Bootstrap columns to size the map and accompanying image, but the image loads too slow (this cannot be resolved at this time), so the container is not the proper size when the map loads.
This causes the map to be half grey. I have attempted to call map.invalidateSize() in the mounted event, but even that must be happening before the image finishes loading.
I have setup a sandbox at: https://codesandbox.io/s/eager-bohr-c3453?file=/src/App.vue
In order to see the bug, you have to view the rendered app at https://c3453.csb.app/ (the internal codesandbox render does not show the problem)
I think I need some way to wait until the image has completed loading (so the BS col is the proper size), then call map.invalidateSize(), but I am not sure how...
You can attach an onload listener on your <img>, so that you can call (again?) your Leaflet map invalidateSize() method.

How to show progressive changing of image from one to another with loading indicator above the image in react-native

I need to show an image (eg:blur image) with loading indicator shows
the image is loading in UI. For eg) In facebook app feed posts are shows as loading before it fetch from server. I need the same.
Any suggestion or any package in react-native?
We have opacity prop and blurRadius prop for image in react native.
so what you can do is....
you can use async function to check if image is completely downloaded ...if yes then setState({downloaded:true}) and then if downloaded is true , based on your choice you can change the opacity to 100% for addon..you can even use activityindicator on top of that.
i hope it solves your problem...
you can also refer to this link : https://medium.com/the-react-native-log/progressive-image-loading-in-react-native-ecc88e724343

React Native. What is inner logic of starting guide screen of mobile app?

We start an app and there you see screen with multiple pages guide about how to use this app etc. How it works?
My suggestions: I have guide key in firebase, I load its value in local store on start. Its default value is 1. 1 - should show it, 0 - shouldn't show it. When I start I show it by default, but when user reaches the last screen, I set value of guide key to 0. And the guide is just a list of scenes (react-native-router-flux). Is it correct or not? What are best practices? What library allows me to create connected screens with dot navigation?
I recently implemented this. I would completely avoid having a guide key in firebase, because you can accomplish it locally. You can use async storage to write a boolean to storage like userDidCompleteGuide. Then, when you startup the app, if that value is not defined when reading from async storage, you know to display the guide component. After completing the guide, save that boolean to async storage. If you already use redux-persist, you can have it persist it through redux too.
I used react-navigation along with fluid transitions with react native for animating shared objects on screen.
On a basic level, it's really easy to create a dot component in react native, so don't use a library for it. It's just a view with a width, height, borderRadius, and color. Change the color to indicate an active or inactive dot depending the screen you're on. You can put a few of them in a row to show sequential steps, having the first one show an active color (like white) and the others be gray. You can then wrap your entire guide screen in a touchable opacity. That way, you can tap anywhere on the screen to advance to the next page of the guide, and when doing so, you can set the second dot to be white and the first to be gray. You could have the dots on both pages, and just change the color and nothing else when changing pages. Or you could have them be the same component and show the actual page above and dynamically change the color based on which page is active using the component state. Just set the state when changing to the next screen using the touchable opacity to indicate which should be active, and then display the page based off of that.

White Flash inbetween Re-rendering Image Views

Not sure if this is a huge issue, but I am not completely sure a solution exists to this.
When creating a slideshow style element, where upon tap you image changes to another image (already prefetched using React Native's image prefetcher) there is this white flash when the screen re-renders (I think?).
Has there been a concrete solution to this? I can't figure out how something like say a snapchat story manages to render a new image completely instant
Has anyone ever done this? is the strategy to just load one image on top of another?