Yes! We have attempted to solve this in the MSFT Team app samples.
Basically, you can collect the images after they have been initially retrieved, and then reference them from the collection instead of the direct call. It's not a perfect pattern, and works best if you add the image column to your Gallery's collection (but also works as a lookup on a Gallery with a direct data call).
You do not want to for a Collect/ForAll to get the images from the connector. I have found this approach to be very slow; given the non-batching nature of the request.
In a nutshell
- Using a triggering mechanism to collect the retrieved photos
- OnHidden of the screen
- After a code block
- OnChange of a TextInput (maybe as a searching mechanism)
- Collect the photos from the Image control of your Gallery
- With the email reference and image
- Have your Gallery check/use the local copy instead of re-retrieving the images each time
Here is a sample of the OnHidden of a screen in one of our newer apps.
ForAll(
galLinksContacts_Contacts.AllItems,
With(
{
varUserName: ThisRecord.lblGalLinksContacts_Contacts_Name.Text,
varUserImage: ThisRecord.imgGalLinksContacts_Contacts_Image.Image
},
If(
IsBlank(
LookUp(
colUserImages,
tblUserName = varUserName
)
),
Collect(
colUserImages,
{
tblUserName: varUserName,
tblUserImage: varUserImage
}
)
)
)
)
Then the Image control in our Gallery has this for its Image property.
IfError(
With(
{varUserName: ThisItem.Email},
With(
{
varUserImage: LookUp(
colUserImages,
tblUserName = varUserName,
tblUserImage
)
},
If(
IsBlankOrError(varUserImage),
If(
IsBlankOrError(varUserName),
Image_DefaultUser,
Office365Users.UserPhotoV2(varUserName)
),
varUserImage
)
)
),
Image_DefaultUser
)
This cuts down on requests significantly, especially with multiple to/from navigation occurring. This allows the retrieved image to be reused within the app as well.
You can and will see it stutter, but this is mostly due to the LookUp happening after the Gallery has been refreshed. You could AddColumn if you were using a local collection and store the image in the collection row, to alleviate this, however.