}
}
+ public class CustomNavigator : Navigator
+ {
+ // Customizes how to handle back navigation.
+ // base.OnBackNavigation() pops the peek page.
+ protected override void OnBackNavigation(BackNavigationEventArgs args)
+ {
+ if (PageCount > 1)
+ {
+ // Deactivates the peek page example before page pop.
+ if (Peek() is IExample currentExample)
+ {
+ currentExample.Deactivate();
+ }
+ }
+
+ // Pops the peek page if navigator has more than one page.
+ // If navigator has only one page, then the program is exited.
+ base.OnBackNavigation(args);
+ }
+ }
+
class Program : NUIApplication
{
private Window window;
private SearchField field;
private List<Gallery> testSource;
- public void OnKeyEvent(object sender, Window.KeyEventArgs e)
- {
- if (e.Key.State == Key.StateType.Up)
- {
- if (e.Key.KeyPressedName == "Escape" || e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "BackSpace")
- {
- if (null != currentExample)
- {
- ExitSample();
- }
- else
- {
- Exit();
- }
- }
- }
- }
-
public void OnSelectionChanged(object sender, SelectionChangedEventArgs ev)
{
Console.WriteLine($"@@@ OnSelectionChanged() {ev.CurrentSelection}");
{
window = GetDefaultWindow();
window.Title = "NUITizenGallery";
- window.KeyEvent += OnKeyEvent;
- navigator = window.GetDefaultNavigator();
+ // In this example, GetDefaultNavigator() has not been called before so default navigator has not been set yet.
+ // Therefore, the following codes for unsetting and disposing the previous default navigator are not required in this example.
+ /*
+ var prevDefaultNavigator = window.GetDefaultNavigator();
+ window.Remove(prevDefaultNavigator);
+ prevDefaultNavigator.Dispose();
+ prevDefaultNavigator = null;
+ */
+
+ // Uses customized navigator to customize how to handle back navigation.
+ navigator = new CustomNavigator()
+ {
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = LayoutParamPolicies.MatchParent,
+ };
+
+ // Sets the customized navigator as the default navigator of the window.
+ window.SetDefaultNavigator(navigator);
}
void OnSearchBtnClicked(object sender, ClickedEventArgs e)
};
navigator = NUIApplication.GetDefaultWindow().GetDefaultNavigator();
- Content = generatePage();
+ Content = generateContent(this);
+ }
+
+ protected override void OnBackNavigation(PageBackNavigationEventArgs eventArgs)
+ {
+ var noButton = new Button()
+ {
+ Text = "No"
+ };
+ noButton.Clicked += (o, e) =>
+ {
+ // Pops the dialog page.
+ Navigator.Pop();
+ };
+
+ var yesButton = new Button()
+ {
+ Text = "Yes"
+ };
+ yesButton.Clicked += (o, e) =>
+ {
+ // Removes the dialog page.
+ Navigator.RemoveAt(Navigator.PageCount - 1);
+
+ // Pops the content page.
+ Navigator.Pop();
+ };
+
+ DialogPage.ShowAlertDialog("", "Do you really want to pop?", new View[] { noButton, yesButton });
}
private ContentPage generatePage()
{
- var page = new ContentPage();
- page.AppBar = new AppBar()
+ var page = new ContentPage()
{
- Title = "NavigatorTestPage",
+ AppBar = new AppBar()
+ {
+ Title = "NavigatorTestPage" + navigator.PageCount.ToString()
+ }
};
+ page.Content = generateContent(page);
+
+ return page;
+ }
+
+ private void updateBackNavigationButtonText(Button button, Navigator navigator)
+ {
+ if (navigator == null)
+ {
+ return;
+ }
+
+ if (navigator.EnableBackNavigation)
+ {
+ button.Text = "Navigator BackNavigation is enabled";
+ }
+ else
+ {
+ button.Text = "Navigator BackNavigation is disabled";
+ }
+ }
+
+ private void updatePageBackNavigationButtonText(Button button, Page page)
+ {
+ if (page == null)
+ {
+ return;
+ }
+
+ if (page.EnableBackNavigation)
+ {
+ button.Text = "Page BackNavigation is enabled";
+ }
+ else
+ {
+ button.Text = "Page BackNavigation is disabled";
+ }
+ }
+
+ private View generateContent(Page page)
+ {
+ if (page == null)
+ {
+ Tizen.Log.Error("NUITEST", "The page should not be null");
+ return null;
+ }
var contentView = new View()
{
CellPadding = new Size2D(0, 10),
},
};
- page.Content = contentView;
var buttonPush = new Button()
{
return;
}
var newPage = generatePage();
- newPage.AppBar.Title = "NavigatorTestPage" + navigator.PageCount.ToString();
navigator.Push(newPage);
};
contentView.Add(buttonPush);
};
contentView.Add(buttonPop);
+ var buttonBackNavigation = new Button()
+ {
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = LayoutParamPolicies.MatchParent,
+ };
+
+ updateBackNavigationButtonText(buttonBackNavigation, navigator);
+
+ buttonBackNavigation.Clicked += (s, e) =>
+ {
+ if (navigator == null)
+ {
+ Tizen.Log.Error("NUITEST", "The page should be pushed to a Navigator");
+ return;
+ }
+
+ navigator.EnableBackNavigation = !navigator.EnableBackNavigation;
+ updateBackNavigationButtonText(buttonBackNavigation, navigator);
+ };
+ contentView.Add(buttonBackNavigation);
+
+ var buttonPageBackNavigation = new Button()
+ {
+ Text = "Page BackNavigation is enabled",
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = LayoutParamPolicies.MatchParent,
+ };
+
+ buttonPageBackNavigation.Clicked += (s, e) =>
+ {
+ if (navigator == null)
+ {
+ Tizen.Log.Error("NUITEST", "The page should be pushed to a Navigator");
+ return;
+ }
+
+ page.EnableBackNavigation = !page.EnableBackNavigation;
+ updatePageBackNavigationButtonText(buttonPageBackNavigation, page);
+ };
+ contentView.Add(buttonPageBackNavigation);
+
+ // Update back navigation button's text when the page is appearing.
+ page.Appearing += (o, e) =>
+ {
+ updateBackNavigationButtonText(buttonBackNavigation, navigator);
+ updatePageBackNavigationButtonText(buttonPageBackNavigation, page);
+ };
+
Color backgroundColor;
switch (navigator.PageCount % numberOfDifferentColor)
{
};
buttonPush.BackgroundColor = backgroundColor;
buttonPop.BackgroundColor = backgroundColor;
- return page;
+ buttonBackNavigation.BackgroundColor = backgroundColor;
+ buttonPageBackNavigation.BackgroundColor = backgroundColor;
+ return contentView;
}
}
}
}
}
+ public class CustomNavigator : Navigator
+ {
+ // Customizes how to handle back navigation.
+ // base.OnBackNavigation() pops the peek page.
+ protected override void OnBackNavigation(BackNavigationEventArgs args)
+ {
+ if (PageCount > 1)
+ {
+ // Deactivates the peek page example before page pop.
+ if (Peek() is IExample currentExample)
+ {
+ currentExample.Deactivate();
+ }
+ }
+
+ // Pops the peek page if navigator has more than one page.
+ // If navigator has only one page, then the program is exited.
+ base.OnBackNavigation(args);
+ }
+ }
+
class Program : NUIApplication
{
private Window window;
private SearchField field;
private List<ControlMenu> testSource;
- public void OnKeyEvent(object sender, Window.KeyEventArgs e)
- {
- // FIXME:: Navigator should provide Back/Escape event processing.
- if (e.Key.State == Key.StateType.Up)
- {
- Log.Info("StyleGuide", $"[{e.Key.KeyPressedName}] is pressed!\n");
- if (e.Key.KeyPressedName == "Escape" || e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "BackSpace")
- {
- if (navigator == null) return;
-
- ExitSample();
-
- if (navigator.PageCount == 0)
- {
- Exit();
- }
- }
- }
- }
-
public void OnSelectionChanged(object sender, SelectionChangedEventArgs ev)
{
Console.WriteLine($"OnSelectionChanged() {ev.CurrentSelection}");
{
window = GetDefaultWindow();
window.Title = "NUI Style Guide";
- window.KeyEvent += OnKeyEvent;
- navigator = window.GetDefaultNavigator();
+ // In this example, GetDefaultNavigator() has not been called before so default navigator has not been set yet.
+ // Therefore, the following codes for unsetting and disposing the previous default navigator are not required in this example.
+ /*
+ var prevDefaultNavigator = window.GetDefaultNavigator();
+ window.Remove(prevDefaultNavigator);
+ prevDefaultNavigator.Dispose();
+ prevDefaultNavigator = null;
+ */
+
+ // Uses customized navigator to customize how to handle back navigation.
+ navigator = new CustomNavigator()
+ {
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = LayoutParamPolicies.MatchParent,
+ };
+
navigator.Popped += (object obj, PoppedEventArgs ev) =>
{
Page top = navigator.Peek();
};
+
+ // Sets the customized navigator as the default navigator of the window.
+ window.SetDefaultNavigator(navigator);
}
void OnSearchBtnClicked(object sender, ClickedEventArgs e)
}
}
- private void ExitSample()
- {
- if (navigator.Peek() is IExample currentExample)
- {
- currentExample.Deactivate();
- }
-
- navigator.Pop();
- // FullGC();
- }
-
private void FullGC()
{
global::System.GC.Collect();