cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate I
Advocate I

Gallery cache issue on iOS

Hi all,

 

I think I've encountered a clientside PowerApps bug where iOS caches the last clicked gallery item. This doesn't affect Android.

 

A vanilla PowerApps app created from a SharePoint list doesn't exhibit the behaviour I'm about to describe.

 

I've lifted my app to sit on collections rather than talking direct to the SharePoint datasource. These collections act as an abstraction layer allowing the app to work offline. An autosave feature polls the network connection to later patch the collection data to the SharePoint list.

 

My app is working as designed but the iOS caching issue is dangerous. A user could inadvertently be passed from the gallery to the wrong record in the detail form to edit and delete.

 

A vanilla PowerApps app works as follows (UniformRecord is a SharePoint list):

 

Browse Screen

    BrowseGallery.Items = SortByColumns(Filter(UniformRecord, StartsWith(ComplianceAssetId, TextSearchBox1.Text)), "ComplianceAssetId", If(SortDescending1, Descending, Ascending))

    NextArrow.OnSelect = Navigate(DetailScreen, ScreenTransition.None)

 

Detail Screen

    DetailForm.DataSource = UniformRecord

    DetailForm.Item = BrowseGallery.Selected

    BackArrow.OnSelect = Navigate(BrowseScreen, ScreenTransition.None)

 

 

For my approach I've populated a collection called colUniformRecordCache from UniformRecord, and configured the gallery and forms to utilise this collection instead of the datasource directly. (yes, I'm aware of the 500 record limit)

 

 

Browse Screen

Browse Screen.OnStart = ClearCollect(colUniformRecordCache, SortByColumns(UniformRecord, "Created", Descending));

   

    BrowseGallery.Items = SortByColumns(Filter(colUniformRecordCache, StartsWith(ComplianceAssetId, TextSearchBox1.Text)), "ComplianceAssetId", If(SortDescending1, Descending, Ascending))
    NextArrow.OnSelect = ClearCollect(colGalRecordSelected, '01_galBrowse'.Selected);
                                         Navigate('02_scrDetail', ScreenTransition.None)

 

Detail Screen
    DetailForm.DataSource = colGalRecordSelected
    DetailForm.Item = First(colGalRecordSelected)
    BackArrow.OnSelect = Navigate('01_scrBrowse', ScreenTransition.None)

 

The behaviour I'm seeing on iOS is each gallery item selection is remembered for the very next gallery selection. 

 

Select record 1, view record 1 on detail screen, return to gallery.

Select record 2, record *1* appears on detail screen, return to gallery.

Select record 2, record 2 appears on detail screen, return to gallery.

Select record 3, record *2* appears on detail screen, return to gallery.

etc.

 

I've experimented with clearing colGalRecordSelected on BackArrow to no avail. This issue doesn't affect Android which suggests my approach should work.

 

Any ideas?

 

Regards,

David

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Power Apps
Power Apps

Re: Gallery cache issue on iOS

I've seen exactly this issue earlier this week, so I guess I know what is going on - assuming that your browse gallery is named '01_galBrowse' (and not BrowseGallery). When you have one item in the gallery that is selected (say, item 1, which is the default selection), and you click the next arrow on item 2, two "events" will happen: the gallery selection will change (so the value of '01_galBrowse'.Selected is updated) and the OnSelect logic on the NextArrow is executed. The order in which those events happened is unspecified, so it's dangerous (as you noticed) to depend on it. As you (and I, a couple of days ago) found out, in iOS the OnSelect happens first and the selection change second, while on Windows (and Android) is the other way around (it's basically a "race condition" between the two events).

 

The solution for that is to not depend on the gallery selection from within the gallery itself; if you want the item that is associated with the NextArrow button, you can use the ThisItem operator instead. If you change the formula to 

NextArrow.OnSelect =
    ClearCollect(colGalRecordSelected, ThisItem);
    Navigate('02_scrDetail', ScreenTransition.None)

Then this race condition won't happen.

 

Hope this helps!

View solution in original post

Highlighted
Advocate I
Advocate I

Re: Gallery cache issue on iOS

Thanks CarlosFigueira,

 

Using "ThisItem" has addressed the issue.

  

For clarity, here is my code with the correct names reflected:

 

**Browse Screen (01_scrBrowse)**
01_scrBrowse.OnStart = ClearCollect(colUniformRecordCache, SortByColumns(UniformRecord, "Created", Descending));
   
    **Gallery (01_galBrowse)**
    01_galBrowse.Items = SortByColumns(Filter(colUniformRecordCache, StartsWith(ComplianceAssetId, TextSearchBox1.Text)), "ComplianceAssetId", If(SortDescending1, Descending, Ascending))
    01_galBrowse.OnSelect = ClearCollect(colGalRecordSelected, ThisItem);
                            Navigate('02_scrDetail', ScreenTransition.None)
 
**Detail Screen (02_scrDetail)**
    **Detail Form (02_frmDetail)**
    02_frmDetail.DataSource = colGalRecordSelected
    02_frmDetail.Item = First(colGalRecordSelected)
    BackArrow.OnSelect = Navigate('01_scrBrowse', ScreenTransition.None)

 

Regards,

David

View solution in original post

3 REPLIES 3
Highlighted
Power Apps
Power Apps

Re: Gallery cache issue on iOS

I've seen exactly this issue earlier this week, so I guess I know what is going on - assuming that your browse gallery is named '01_galBrowse' (and not BrowseGallery). When you have one item in the gallery that is selected (say, item 1, which is the default selection), and you click the next arrow on item 2, two "events" will happen: the gallery selection will change (so the value of '01_galBrowse'.Selected is updated) and the OnSelect logic on the NextArrow is executed. The order in which those events happened is unspecified, so it's dangerous (as you noticed) to depend on it. As you (and I, a couple of days ago) found out, in iOS the OnSelect happens first and the selection change second, while on Windows (and Android) is the other way around (it's basically a "race condition" between the two events).

 

The solution for that is to not depend on the gallery selection from within the gallery itself; if you want the item that is associated with the NextArrow button, you can use the ThisItem operator instead. If you change the formula to 

NextArrow.OnSelect =
    ClearCollect(colGalRecordSelected, ThisItem);
    Navigate('02_scrDetail', ScreenTransition.None)

Then this race condition won't happen.

 

Hope this helps!

View solution in original post

Highlighted
Advocate I
Advocate I

Re: Gallery cache issue on iOS

Thanks CarlosFigueira,

 

Using "ThisItem" has addressed the issue.

  

For clarity, here is my code with the correct names reflected:

 

**Browse Screen (01_scrBrowse)**
01_scrBrowse.OnStart = ClearCollect(colUniformRecordCache, SortByColumns(UniformRecord, "Created", Descending));
   
    **Gallery (01_galBrowse)**
    01_galBrowse.Items = SortByColumns(Filter(colUniformRecordCache, StartsWith(ComplianceAssetId, TextSearchBox1.Text)), "ComplianceAssetId", If(SortDescending1, Descending, Ascending))
    01_galBrowse.OnSelect = ClearCollect(colGalRecordSelected, ThisItem);
                            Navigate('02_scrDetail', ScreenTransition.None)
 
**Detail Screen (02_scrDetail)**
    **Detail Form (02_frmDetail)**
    02_frmDetail.DataSource = colGalRecordSelected
    02_frmDetail.Item = First(colGalRecordSelected)
    BackArrow.OnSelect = Navigate('01_scrBrowse', ScreenTransition.None)

 

Regards,

David

View solution in original post

Highlighted
Anonymous
Not applicable

Re: Gallery cache issue on iOS

This has been driving me crazy for days - thanks for the simple solution!

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

Top Solution Authors
Top Kudoed Authors
Users online (6,752)