Skip to content

Commit

Permalink
[NUI] Update NUISettings to guide how to use Navigator in Widget
Browse files Browse the repository at this point in the history
To pass data between Widgets, data is passed from Widget to Main app and
Main app passes the data to another Widget.
Since this is difficult to support, NUISettings guides how to use
Navigator in Widget.
By using Widget's own Navigator, Widget knows its Navigator and its
Pages. So Widget can pass data between its Pages easily.
  • Loading branch information
Jaehyun-Cho authored and dongsug-song committed Aug 29, 2022
1 parent dc56c4b commit 4be7b86
Show file tree
Hide file tree
Showing 2 changed files with 239 additions and 95 deletions.
68 changes: 59 additions & 9 deletions test/NUISettings/NUISettings/NUISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,83 @@ void Initialize()
int widgetWidth = window.Size.Width;
int widgetHeight = window.Size.Height;

Navigator navigator = window.GetDefaultNavigator();

Bundle bundle = new Bundle();
bundle.AddItem(" ", " ");
String encodedBundle = bundle.Encode();

// Add Widget of "secondPage@NUISettingsReset" in advance to avoid loading pending.
AddWidget(out secondPageWidgetView, "secondPage@NUISettingsReset", encodedBundle, widgetWidth, widgetHeight, 0.0f);

Navigator navigator = window.GetDefaultNavigator();
// Add Widget of "thirdPage@NUISettingsReset" in advance to avoid loading pending.
AddWidget(out thirdPageWidgetView, "thirdPage@NUISettingsReset", encodedBundle, widgetWidth, widgetHeight, 0.0f);

var button = new Button()
// Add Widget of "fourthPage@NUISettingsReset" in advance to avoid loading pending.
AddWidget(out fourthPageWidgetView, "fourthPage@NUISettingsReset", encodedBundle, widgetWidth, widgetHeight, 0.0f);

var content = new View()
{
Layout = new LinearLayout()
{
LinearOrientation = LinearLayout.Orientation.Vertical,
CellPadding = new Size2D(0, 20),
},
WidthSpecification = LayoutParamPolicies.MatchParent,
HeightSpecification = LayoutParamPolicies.MatchParent,
};

var secondPageButton = new Button()
{
Text = "Click to Second Page",
WidthSpecification = LayoutParamPolicies.MatchParent,
HeightSpecification = LayoutParamPolicies.MatchParent,
};
button.Clicked += (o, e) =>
secondPageButton.Clicked += (o, e) =>
{
var page = new ContentPage();
page.Content = secondPageWidgetView;
var page = new ContentPage()
{
Content = secondPageWidgetView,
};
navigator.Push(page);
};
content.Add(secondPageButton);

var thirdPageButton = new Button()
{
Text = "Click to Third Page",
WidthSpecification = LayoutParamPolicies.MatchParent,
HeightSpecification = LayoutParamPolicies.MatchParent,
};
thirdPageButton.Clicked += (o, e) =>
{
var page = new ContentPage()
{
Content = thirdPageWidgetView,
};
navigator.Push(page);
};
content.Add(thirdPageButton);

var fourthPageButton = new Button()
{
Text = "Click to Fourth Page",
WidthSpecification = LayoutParamPolicies.MatchParent,
HeightSpecification = LayoutParamPolicies.MatchParent,
};
fourthPageButton.Clicked += (o, e) =>
{
var page = new DialogPage()
{
Content = fourthPageWidgetView,
EnableScrim = false, // fourthPageWidgetView's DialogPage.Scrim is used, so this DialogPage.Scrim should not be used.
};
navigator.Push(page);
};
content.Add(fourthPageButton);

// Push the first page.
PushContentPage("First Page", button);
PushContentPage("First Page", content);
}

void AddWidget(out WidgetView widgetView, string widgetID, string contentInfo, int width, int height, float updatePeriod)
Expand All @@ -77,9 +130,6 @@ void PushContentPage(string title, View content)
Window window = GetDefaultWindow();
Navigator navigator = window.GetDefaultNavigator();

window.KeyEvent += OnKeyEvent;
window.TouchEvent += OnTouchEvent;

var page = new ContentPage()
{
AppBar = new AppBar()
Expand Down
Loading

0 comments on commit 4be7b86

Please sign in to comment.