Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit b5b9404

Browse files
ylatuyaPureWeen
authored andcommitted
[GTK] Fix visibility of hidden pages in the stack (#3904)
When navigating to a new page, we should hide the previous content and show the new one so that the previous page renderer is not taken in account for redraws and resizes
1 parent 33ea577 commit b5b9404

3 files changed

Lines changed: 21 additions & 35 deletions

File tree

Xamarin.Forms.Platform.GTK/Controls/Page.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Gdk;
22
using Gtk;
33
using System;
4+
using System.Linq;
45
using Xamarin.Forms.Platform.GTK.Extensions;
56

67
namespace Xamarin.Forms.Platform.GTK.Controls
@@ -93,6 +94,22 @@ public void SetBackgroundImage(string backgroundImagePath)
9394
}
9495
}
9596

97+
public void PushModal(Widget modal)
98+
{
99+
Children.Last().Hide();
100+
Attach(modal, 0, 1, 0, 1);
101+
modal.ShowAll();
102+
}
103+
104+
public void PopModal(Widget modal)
105+
{
106+
if (Children.Length > 0)
107+
{
108+
Remove(modal);
109+
}
110+
Children.Last().Show();
111+
}
112+
96113
public override void Dispose()
97114
{
98115
base.Dispose();

Xamarin.Forms.Platform.GTK/Platform.cs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -181,28 +181,7 @@ Task<Page> INavigation.PopModalAsync(bool animated)
181181

182182
Device.BeginInvokeOnMainThread(() =>
183183
{
184-
if (pageControl != null)
185-
{
186-
var page = pageControl.Control;
187-
188-
if (page != null)
189-
{
190-
if (page.Children.Length > 0)
191-
{
192-
page.Remove(modalPage);
193-
}
194-
195-
if (page.Children != null)
196-
{
197-
foreach (var child in page.Children)
198-
{
199-
child.ShowAll();
200-
}
201-
202-
page.ShowAll();
203-
}
204-
}
205-
}
184+
pageControl?.Control?.PopModal(modalPage);
206185

207186
DisposeModelAndChildrenRenderers(modal);
208187
});
@@ -258,17 +237,7 @@ Task INavigation.PushModalAsync(Page modal, bool animated)
258237

259238
if (page != null)
260239
{
261-
page.Attach(modalRenderer.Container, 0, 1, 0, 1);
262-
263-
if (page.Children != null)
264-
{
265-
foreach (var child in page.Children)
266-
{
267-
child.ShowAll();
268-
}
269-
270-
page.ShowAll();
271-
}
240+
page.PushModal(modalRenderer.Container);
272241
}
273242
}
274243
});

Xamarin.Forms.Platform.GTK/Renderers/NavigationPageRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ private async Task<bool> AddPageAsync(Page page, bool animated)
330330
if (oldPage != null && Platform.GetRenderer(oldPage) != null)
331331
{
332332
var oldPageRenderer = Platform.GetRenderer(oldPage);
333-
oldPageRenderer.Container.Sensitive = false;
333+
oldPageRenderer.Container.Visible = false;
334334
}
335335

336336
return true;
@@ -343,7 +343,7 @@ private async Task RemovePageAsync(Page page, bool removeFromStack, bool animate
343343
if (oldPage != null && Platform.GetRenderer(oldPage) != null)
344344
{
345345
var oldPageRenderer = Platform.GetRenderer(oldPage);
346-
oldPageRenderer.Container.Sensitive = true;
346+
oldPageRenderer.Container.Visible = true;
347347
}
348348

349349
(page as IPageController)?.SendDisappearing();

0 commit comments

Comments
 (0)