From 5b7260a1e1021139dad5e79e82e5504ef36486cd Mon Sep 17 00:00:00 2001 From: "dongsug.song" Date: Tue, 15 Mar 2022 16:10:55 +0900 Subject: [PATCH] Revert "[DO NOT REVIEW][TEST][NUI] key focus default algorithm test" This reverts commit bf89dd9e1d0b37d2ecbb65cf47d0ed65c4e693b1. --- src/Tizen.NUI.Components/Controls/Button.cs | 3 - .../Controls/Navigation/Navigator.cs | 93 ++---------------- .../Controls/Navigation/Page.cs | 2 - src/Tizen.NUI/src/public/Input/FocusManager.cs | 7 +- .../Tizen.NUI.StyleGuide/Examples/ButtonExample.cs | 6 +- .../ScrollableBaseDirectionExample.cs | 1 + .../ScrollableBase/ScrollableBaseExample.cs | 6 +- test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs | 107 +++++++++++++++------ 8 files changed, 99 insertions(+), 126 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/Button.cs b/src/Tizen.NUI.Components/Controls/Button.cs index 752b52b..70595df 100755 --- a/src/Tizen.NUI.Components/Controls/Button.cs +++ b/src/Tizen.NUI.Components/Controls/Button.cs @@ -193,7 +193,6 @@ namespace Tizen.NUI.Components /// 6 public Button() : base() { - Focusable = true; } /// @@ -203,7 +202,6 @@ namespace Tizen.NUI.Components /// 8 public Button(string style) : base(style) { - Focusable = true; } /// @@ -213,7 +211,6 @@ namespace Tizen.NUI.Components /// 8 public Button(ButtonStyle buttonStyle) : base(buttonStyle) { - Focusable = true; } /// diff --git a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs index 6b6b12b..a60dc14 100755 --- a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs +++ b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs @@ -228,7 +228,7 @@ namespace Tizen.NUI.Components { if (page is DialogPage == false) { - topPage.SetVisible(false); + topPage.SetVisible(false); } // Need to update Content of the new page @@ -338,20 +338,6 @@ namespace Tizen.NUI.Components page.InvokeAppearing(); curTop.InvokeDisappearing(); - //test. - // if (FocusManager.Instance.IsDefaultAlgorithmEnabled()) - // { - // curTop.LastFocusedView = FocusManager.Instance.GetCurrentFocusView(); - // if(page.LastFocusedView) - // { - // FocusManager.Instance.SetCurrentFocusView(page.LastFocusedView); - // } - // else - // { - // FocusManager.Instance.ClearFocus(); - // } - // } - //TODO: The following transition codes will be replaced with view transition. InitializeAnimation(); @@ -382,15 +368,6 @@ namespace Tizen.NUI.Components //Invoke Page events page.InvokeAppeared(); NotifyAccessibilityStatesChangeOfPages(curTop, page); - - //test. - // if (FocusManager.Instance.IsDefaultAlgorithmEnabled()) - // { - // FocusManager.Instance.ClearFocus(); - // FocusManager.Instance.MoveFocus(View.FocusDirection.Down); - // //FocusManager.Instance.MoveFocus(View.FocusDirection.Down); - // } - }; newAnimation.Play(); } @@ -398,14 +375,6 @@ namespace Tizen.NUI.Components { ShowContentOfPage(page); } - - //test. - // if (FocusManager.Instance.IsDefaultAlgorithmEnabled()) - // { - // FocusManager.Instance.ClearFocus(); - // FocusManager.Instance.MoveFocus(View.FocusDirection.Down); - // FocusManager.Instance.MoveFocus(View.FocusDirection.Down); - // } } /// @@ -445,20 +414,6 @@ namespace Tizen.NUI.Components newTop.InvokeAppearing(); curTop.InvokeDisappearing(); - //test. - // if (FocusManager.Instance.IsDefaultAlgorithmEnabled()) - // { - // curTop.LastFocusedView = FocusManager.Instance.GetCurrentFocusView(); - // if(newTop.LastFocusedView) - // { - // FocusManager.Instance.SetCurrentFocusView(newTop.LastFocusedView); - // } - // else - // { - // FocusManager.Instance.ClearFocus(); - // } - // } - //TODO: The following transition codes will be replaced with view transition. InitializeAnimation(); @@ -493,17 +448,6 @@ namespace Tizen.NUI.Components //Invoke Page events newTop.InvokeAppeared(); - - - //test. - // if (FocusManager.Instance.IsDefaultAlgorithmEnabled()) - // { - // FocusManager.Instance.ClearFocus(); - // FocusManager.Instance.MoveFocus(View.FocusDirection.Down); - // //FocusManager.Instance.MoveFocus(View.FocusDirection.Down); - // } - - }; newAnimation.Play(); } @@ -512,23 +456,6 @@ namespace Tizen.NUI.Components Remove(curTop); } - //test. - // if (FocusManager.Instance.IsDefaultAlgorithmEnabled()) - // { - // if(newTop.LastFocusedView) - // { - // FocusManager.Instance.SetCurrentFocusView(newTop.LastFocusedView); - // } - // } - - // //test. - // if (FocusManager.Instance.IsDefaultAlgorithmEnabled()) - // { - // FocusManager.Instance.ClearFocus(); - // FocusManager.Instance.MoveFocus(View.FocusDirection.Down); - // FocusManager.Instance.MoveFocus(View.FocusDirection.Down); - // } - return curTop; } @@ -814,12 +741,12 @@ namespace Tizen.NUI.Components RetrieveTaggedViews(taggedViewsInCurrentTopPage, currentTopPage, true); List> sameTaggedViewPair = new List>(); - foreach (View currentTopPageView in taggedViewsInCurrentTopPage) + foreach(View currentTopPageView in taggedViewsInCurrentTopPage) { bool findPair = false; - foreach (View newTopPageView in taggedViewsInNewTopPage) + foreach(View newTopPageView in taggedViewsInNewTopPage) { - if ((currentTopPageView.TransitionOptions != null) && (newTopPageView.TransitionOptions != null) && + if((currentTopPageView.TransitionOptions != null) && (newTopPageView.TransitionOptions != null) && currentTopPageView.TransitionOptions?.TransitionTag == newTopPageView.TransitionOptions?.TransitionTag) { sameTaggedViewPair.Add(new KeyValuePair(currentTopPageView, newTopPageView)); @@ -827,21 +754,21 @@ namespace Tizen.NUI.Components break; } } - if (findPair) + if(findPair) { taggedViewsInNewTopPage.Remove(sameTaggedViewPair[sameTaggedViewPair.Count - 1].Value); } } - foreach (KeyValuePair pair in sameTaggedViewPair) + foreach(KeyValuePair pair in sameTaggedViewPair) { taggedViewsInCurrentTopPage.Remove(pair.Key); } TransitionSet newTransitionSet = new TransitionSet(); - foreach (KeyValuePair pair in sameTaggedViewPair) + foreach(KeyValuePair pair in sameTaggedViewPair) { TransitionItem pairTransition = transition.CreateTransition(pair.Key, pair.Value, pushTransition); - if (pair.Value.TransitionOptions?.TransitionWithChild ?? false) + if(pair.Value.TransitionOptions?.TransitionWithChild ?? false) { pairTransition.TransitionWithChild = true; } @@ -850,11 +777,11 @@ namespace Tizen.NUI.Components newTransitionSet.Finished += (object sender, EventArgs e) => { - if (newTopPage.Layout != null) + if(newTopPage.Layout != null) { newTopPage.Layout.RequestLayout(); } - if (currentTopPage.Layout != null) + if(currentTopPage.Layout != null) { currentTopPage.Layout.RequestLayout(); } diff --git a/src/Tizen.NUI.Components/Controls/Navigation/Page.cs b/src/Tizen.NUI.Components/Controls/Navigation/Page.cs index e2d7197..fba9475 100755 --- a/src/Tizen.NUI.Components/Controls/Navigation/Page.cs +++ b/src/Tizen.NUI.Components/Controls/Navigation/Page.cs @@ -94,8 +94,6 @@ namespace Tizen.NUI.Components return instance.InternalDisappearingTransition; }); - internal BaseComponents.View LastFocusedView = null; - private Navigator navigator = null; // Default transition is Fade. diff --git a/src/Tizen.NUI/src/public/Input/FocusManager.cs b/src/Tizen.NUI/src/public/Input/FocusManager.cs index cc27082..204d898 100755 --- a/src/Tizen.NUI/src/public/Input/FocusManager.cs +++ b/src/Tizen.NUI/src/public/Input/FocusManager.cs @@ -72,8 +72,6 @@ namespace Tizen.NUI [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void FocusedViewEnterKeyEventCallback2(IntPtr view); - private View internalFocusIndicator = null; - /// /// PreFocusChange will be triggered before the focus is going to be changed.
/// The FocusManager makes the best guess for which view to focus towards the given direction, but applications might want to change that.
@@ -476,15 +474,14 @@ namespace Tizen.NUI { Interop.FocusManager.SetFocusIndicatorActor(SwigCPtr, View.getCPtr(indicator)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - internalFocusIndicator = indicator; } internal View GetFocusIndicatorView() { //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = Interop.FocusManager.GetFocusIndicatorActor(SwigCPtr); - internalFocusIndicator = this.GetInstanceSafely(cPtr); - return internalFocusIndicator; + View ret = this.GetInstanceSafely(cPtr); + return ret; } internal PreFocusChangeSignal PreFocusChangeSignal() diff --git a/test/Tizen.NUI.StyleGuide/Examples/ButtonExample.cs b/test/Tizen.NUI.StyleGuide/Examples/ButtonExample.cs index 38b4e5a..a73ffd8 100644 --- a/test/Tizen.NUI.StyleGuide/Examples/ButtonExample.cs +++ b/test/Tizen.NUI.StyleGuide/Examples/ButtonExample.cs @@ -28,11 +28,11 @@ namespace Tizen.NUI.StyleGuide private Window window; public void Activate() { - Log.Info(this.GetType().Name, $"this.GetType().Name={this.GetType().Name}, Activate()\n"); + Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Activate()\n"); } public void Deactivate() { - Log.Info(this.GetType().Name, $"this.GetType().Name={this.GetType().Name}, Deactivate()\n"); + Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Deactivate()\n"); window = null; } @@ -71,6 +71,7 @@ namespace Tizen.NUI.StyleGuide { Text = "Enabled" }; + enabledButton.EnableFocus(); enabledButton.Clicked += (object obj, ClickedEventArgs ev) => { Log.Info(this.GetType().Name, "Enabled Button Clicked\n"); @@ -95,6 +96,7 @@ namespace Tizen.NUI.StyleGuide Text = "Unselected", IsSelectable = true, }; + selectableButton.EnableFocus(); selectableButton.Clicked += (object obj, ClickedEventArgs ev) => { Log.Info(this.GetType().Name, "Selected Button Clicked\n"); diff --git a/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseDirectionExample.cs b/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseDirectionExample.cs index 610d0ab..2ab5934 100644 --- a/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseDirectionExample.cs +++ b/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseDirectionExample.cs @@ -81,6 +81,7 @@ namespace Tizen.NUI.StyleGuide colorView.WidthSpecification = (isHorizontal? 200 : LayoutParamPolicies.MatchParent); colorView.HeightSpecification = (isHorizontal? LayoutParamPolicies.MatchParent : 200); colorView.BackgroundColor = new Color((float)rnd.Next(256)/256f, (float)rnd.Next(256)/256f, (float)rnd.Next(256)/256f, 1); + colorView.EnableFocus(); scrollView.Add(colorView); } diff --git a/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseExample.cs b/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseExample.cs index 1208fd8..6db39d0 100644 --- a/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseExample.cs +++ b/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseExample.cs @@ -31,11 +31,11 @@ namespace Tizen.NUI.StyleGuide private List directionMenu; public void Activate() { - Log.Info(this.GetType().Name, $"this.GetType().Name={this.GetType().Name}, Activate()\n"); + Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Activate()\n"); } public void Deactivate() { - Log.Info(this.GetType().Name, $"this.GetType().Name={this.GetType().Name}, Deactivate()\n"); + Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Deactivate()\n"); window = null; directionMenu = null; } @@ -73,6 +73,7 @@ namespace Tizen.NUI.StyleGuide }; item.Label.SetBinding(TextLabel.TextProperty, "Direction"); item.Label.HorizontalAlignment = HorizontalAlignment.Begin; + item.EnableFocus(); return item; }), ScrollingDirection = ScrollableBase.Direction.Vertical, @@ -87,6 +88,7 @@ namespace Tizen.NUI.StyleGuide Page scrollDirPage = new ScrollableBaseDirectionExample(directionItem.Direction); window = NUIApplication.GetDefaultWindow(); window.GetDefaultNavigator().Push(scrollDirPage); + FocusableExtension.SetFocusOnPage(scrollDirPage); } directionListView.SelectedItem = null; }; diff --git a/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs b/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs index def75a4..ffa0663 100644 --- a/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs +++ b/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs @@ -26,6 +26,67 @@ using System.Reflection; namespace Tizen.NUI.StyleGuide { + + /// Helder static extension class for Focusable. + /// NUI default behavior is unfocusable in key or touch, + /// this class help to setting focusable features easily. + public static class FocusableExtension + { + public static FocusManager FocusManager; + public static void EnableFocus(this View view) + { + view.Focusable = true; + view.FocusableInTouch = true; + } + + public static void EnableAutoFocusable() + { + FocusManager = FocusManager.Instance; + FocusManager.EnableDefaultAlgorithm(true); + FocusManager.FocusIndicator = new View() + { + PositionUsesPivotPoint = true, + PivotPoint = new Position(0, 0, 0), + WidthResizePolicy = ResizePolicyType.FillToParent, + HeightResizePolicy = ResizePolicyType.FillToParent, + BorderlineColor = Color.Orange, + BorderlineWidth = 4.0f, + BorderlineOffset = -1f, + BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.2f), + }; + } + + public static void SetFocusOnPage(Page page) + { + View focusCandidate = null; + if (page == null) return; + + if (page is ContentPage contentPage) + { + focusCandidate = contentPage.AppBar?.NavigationContent; + focusCandidate.Focusable = true; + } + + if (focusCandidate == null) + { + foreach (View child in page.Children) + { + if (child.Focusable) + { + focusCandidate = child; + } + } + } + + Log.Info("FocusableExtension", $"Focus candidate {focusCandidate}\n"); + + if (focusCandidate != null) + { + FocusManager.SetCurrentFocusView(focusCandidate); + } + } + } + public class SearchField : View { public TextField SearchTextField; @@ -47,12 +108,14 @@ namespace Tizen.NUI.StyleGuide var searchTextBox = CreateSearchText(); SearchTextField = CreateTextField(); + SearchTextField.EnableFocus(); var underline = CreateUnderline(); searchTextBox.Add(SearchTextField); searchTextBox.Add(underline); SearchButton = CreateSearchButton(); + SearchButton.EnableFocus(); Add(searchTextBox); Add(SearchButton); @@ -80,7 +143,6 @@ namespace Tizen.NUI.StyleGuide WidthSpecification = LayoutParamPolicies.MatchParent, HeightSpecification = LayoutParamPolicies.WrapContent, MinimumSize = new Size2D(0, 40), - Focusable = true, //BaseComponents' Focusable is false as a default value, true should be set to navigate key focus and edit text. }; } @@ -156,7 +218,7 @@ namespace Tizen.NUI.StyleGuide foreach (Type type in assembly.GetTypes()) { - Console.WriteLine($"type.Name={type.Name}, type.FullName={type.FullName}"); + Console.WriteLine($"@@@ type.Name={type.Name}, type.FullName={type.FullName}"); if (exampleType.IsAssignableFrom(type) && type.Name != "SampleMain" && this.GetType() != type && type.IsClass) { NamePool.Add(new Tuple(type.Name, type.FullName)); @@ -190,7 +252,7 @@ namespace Tizen.NUI.StyleGuide if (navigator.PageCount == 0) { - Exit(); + Exit(); } } } @@ -198,13 +260,13 @@ namespace Tizen.NUI.StyleGuide public void OnSelectionChanged(object sender, SelectionChangedEventArgs ev) { - Console.WriteLine($"OnSelectionChanged() {ev.CurrentSelection}"); + Console.WriteLine($"@@@ OnSelectionChanged() {ev.CurrentSelection}"); if (ev.CurrentSelection.Count == 0) return; if (ev.CurrentSelection[0] is ControlMenu selItem) { - Console.WriteLine($"selItem.Name={selItem.Name}, selItem.FullName={selItem.FullName}"); + Console.WriteLine($"@@@ selItem.Name={selItem.Name}, selItem.FullName={selItem.FullName}"); RunSample(selItem?.FullName); } colView.SelectedItem = null; @@ -215,27 +277,6 @@ namespace Tizen.NUI.StyleGuide base.OnCreate(); Initialize(); SetMainPage(); - - focusManager = FocusManager.Instance; - - //set user customized focus indicator - if (!focusManager.FocusIndicator) - { - focusManager.FocusIndicator = new View() - { - PositionUsesPivotPoint = true, - PivotPoint = new Position(0, 0, 0), - WidthResizePolicy = ResizePolicyType.FillToParent, - HeightResizePolicy = ResizePolicyType.FillToParent, - BorderlineColor = Color.Orange, - BorderlineWidth = 4.0f, - BorderlineOffset = -1f, - BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.2f), - }; - } - - //enable FocusManger default algorithm - focusManager.EnableDefaultAlgorithm(true); } private void Initialize() { @@ -243,10 +284,13 @@ namespace Tizen.NUI.StyleGuide window.Title = "NUI Style Guide"; window.KeyEvent += OnKeyEvent; + FocusableExtension.EnableAutoFocusable(); + navigator = window.GetDefaultNavigator(); navigator.Popped += (object obj, PoppedEventArgs ev) => { Page top = navigator.Peek(); + FocusableExtension.SetFocusOnPage(top); }; } @@ -275,6 +319,7 @@ namespace Tizen.NUI.StyleGuide var appBarStyle = ThemeManager.GetStyle("Tizen.NUI.Components.AppBar"); var moreButton = new Button(((AppBarStyle)appBarStyle).BackButton); moreButton.Icon.ResourceUrl = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "menu.png"; + moreButton.EnableFocus(); appBar.NavigationContent = moreButton; @@ -314,7 +359,7 @@ namespace Tizen.NUI.StyleGuide }; item.Label.SetBinding(TextLabel.TextProperty, "ViewLabel"); item.Label.HorizontalAlignment = HorizontalAlignment.Begin; - item.Focusable = true; //BaseComponents' Focusable is false as a default value, true should be set to navigate key focus. + item.EnableFocus(); return item; }), Header = myTitle, @@ -333,8 +378,10 @@ namespace Tizen.NUI.StyleGuide AppBar = appBar, Content = pageContent, }; + page.Focusable = true; navigator.Push(page); + FocusableExtension.SetFocusOnPage(page); } private void RunSample(string name) @@ -342,19 +389,21 @@ namespace Tizen.NUI.StyleGuide IExample example = typeof(Program).Assembly?.CreateInstance(name) as IExample; - Console.WriteLine($"typeof(Program).Assembly={typeof(Program).Assembly}, name={name}"); + Console.WriteLine($"@@@ typeof(Program).Assembly={typeof(Program).Assembly}, name={name}"); if (example != null) { example.Activate(); if (example is Page examplePage) { + examplePage.Focusable = true; navigator.Push(examplePage); + FocusableExtension.SetFocusOnPage(examplePage); } } else { - Console.WriteLine($"examle is null!"); + Console.WriteLine($"@@@ examle is null!"); } } -- 2.7.4