Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
FIx CircleScroller and PopupEntry Issues (#108)
Browse files Browse the repository at this point in the history
* Fix Scroller for add padding

* Apply padding feature to CircleScrollView

* Fix PopupEntry Issues

Fix removed TextStyle after recreated the PopupEntry. #81
Fix TextChanged and Completed events. #101
Fix Keyboard. #104

* Merge duplicated case from VisiblePolicy

* Remove useless conditions from PopupEntry
  • Loading branch information
idkiller authored Aug 31, 2018
1 parent 70dda92 commit e9a588f
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Tizen.Wearable.CircularUI.Forms.Renderer
{
class CircleScrollViewRenderer : ViewRenderer<CircleScrollView, ElmSharp.Wearable.CircleScroller>
{
ElmSharp.EvasObject _content;
Xamarin.Forms.Platform.Tizen.Native.Box _scrollCanvas;
ElmSharp.SmartEvent _scrollAnimationStart, _scrollAnimationStop;
bool _isAnimation;
TaskCompletionSource<bool> _animationTaskComplateSource;
Expand All @@ -46,6 +46,9 @@ protected override void OnElementChanged(ElementChangedEventArgs<CircleScrollVie
SetNativeControl(new ElmSharp.Wearable.CircleScroller(Xamarin.Forms.Platform.Tizen.Forms.NativeParent, surface));
InitControl();
Control.Scrolled += OnScrolled;
_scrollCanvas = new Xamarin.Forms.Platform.Tizen.Native.Box(Control);
_scrollCanvas.LayoutUpdated += OnContentLayoutUpdated;
Control.SetContent(_scrollCanvas);
}
if (e.OldElement != null)
{
Expand All @@ -70,6 +73,14 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
{
UpdateContentSize();
}
else if (ScrollView.VerticalScrollBarVisibilityProperty.PropertyName == e.PropertyName)
{
UpdateVerticalScrollBarVisibility();
}
else if (ScrollView.HorizontalScrollBarVisibilityProperty.PropertyName == e.PropertyName)
{
UpdateHorizontalScrollBarVisibility();
}
base.OnElementPropertyChanged(sender, e);
}

Expand All @@ -85,6 +96,10 @@ protected override void Dispose(bool disposing)
{
Control.Scrolled -= OnScrolled;
}
if (_scrollCanvas != null)
{
_scrollCanvas.LayoutUpdated -= OnContentLayoutUpdated;
}
}
base.Dispose(disposing);
}
Expand All @@ -94,6 +109,31 @@ void UpdateAll()
UpdateOrientation();
}

void UpdateVerticalScrollBarVisibility()
{
Control.VerticalScrollBarVisiblePolicy = ScrollBarVisibilityToTizen(Element.VerticalScrollBarVisibility);
}

void UpdateHorizontalScrollBarVisibility()
{
var orientation = Element.Orientation;
if (orientation == ScrollOrientation.Horizontal || orientation == ScrollOrientation.Both)
Control.HorizontalScrollBarVisiblePolicy = ScrollBarVisibilityToTizen(Element.HorizontalScrollBarVisibility);
}

ScrollBarVisiblePolicy ScrollBarVisibilityToTizen(ScrollBarVisibility visibility)
{
switch (visibility)
{
case ScrollBarVisibility.Always:
return ScrollBarVisiblePolicy.Visible;
case ScrollBarVisibility.Never:
return ScrollBarVisiblePolicy.Invisible;
default:
return ScrollBarVisiblePolicy.Auto;
}
}

async void OnScrollRequestedAsync(object sender, ScrollToRequestedEventArgs e)
{
var x = e.ScrollX;
Expand All @@ -117,34 +157,18 @@ void OnScrolled(object sender, EventArgs e)

void OnContent()
{
if (_content != null)
{
if (_content is Xamarin.Forms.Platform.Tizen.Native.Box contentBox)
{
contentBox.LayoutUpdated -= OnContentLayoutUpdated;
}
Control.SetContent(null, true);
_content.Unrealize();
_content = null;
}
_scrollCanvas.UnPackAll();
if (Element.Content != null)
{
_content = Xamarin.Forms.Platform.Tizen.Platform.GetOrCreateRenderer(Element.Content).NativeView;
if (_content is Xamarin.Forms.Platform.Tizen.Native.Box contentBox)
{
contentBox.LayoutUpdated += OnContentLayoutUpdated;
}
Control.SetContent(_content, true);
_scrollCanvas.PackEnd(Platform.GetOrCreateRenderer(Element.Content).NativeView);
UpdateContentSize();
}
}

void UpdateContentSize()
{
if (_content == null) return;

_content.MinimumWidth = Xamarin.Forms.Platform.Tizen.Forms.ConvertToScaledPixel(Element.ContentSize.Width);
_content.MinimumHeight = Xamarin.Forms.Platform.Tizen.Forms.ConvertToScaledPixel(Element.ContentSize.Height);
_scrollCanvas.MinimumWidth = Xamarin.Forms.Platform.Tizen.Forms.ConvertToScaledPixel(Element.ContentSize.Width + Element.Padding.HorizontalThickness);
_scrollCanvas.MinimumHeight = Xamarin.Forms.Platform.Tizen.Forms.ConvertToScaledPixel(Element.ContentSize.Height + Element.Padding.VerticalThickness);

Device.BeginInvokeOnMainThread(() =>
{
Expand Down
54 changes: 38 additions & 16 deletions src/Tizen.Wearable.CircularUI.Forms.Renderer/PopupEntryRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

using ElmSharp;
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
Expand All @@ -33,13 +34,18 @@ public class PopupEntryRenderer : EntryRenderer

ElmSharp.Color DefaultColor { get; set; }

protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Entry> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
Control.IsEditable = false;
Control.SetInputPanelEnabled(false);
Control.Clicked += OnClicked;

// Set Text again for apply text style because IsEditable reset the style of text
Control.Text = string.Empty;
Control.Text = Element.Text;
}
}

Expand All @@ -58,11 +64,23 @@ protected override void Dispose(bool disposing)

void OnClicked(object sender, EventArgs e) => ShowPopup();

Window FindWindow(EvasObject obj)
{
EvasObject parent = obj.Parent;
while (!(parent is Window) && parent != null)
{
parent = parent.Parent;
}
return parent as Window;
}

void CreatePopup()
{
var rect = Xamarin.Forms.Platform.Tizen.Forms.NativeParent.Geometry;

_editorPopup = new ElmSharp.Background(Xamarin.Forms.Platform.Tizen.Forms.NativeParent)
var root = FindWindow(Xamarin.Forms.Platform.Tizen.Forms.NativeParent);

_editorPopup = new ElmSharp.Background(root)
{
Geometry = rect
};
Expand All @@ -77,15 +95,13 @@ void CreatePopup()
_editor = new Xamarin.Forms.Platform.Tizen.Native.Entry(layout);
_editor.IsSingleLine = true;
_editor.Scrollable = true;
_editor.PredictionAllowed = false;
_editor.SetInputPanelEnabled(false);
_editor.ShowInputPanel();
_editor.AllowFocus(true);
_editor.Show();

_editor.SetInputPanelReturnKeyType(ElmSharp.InputPanelReturnKeyType.Done);

_editor.SetInputPanelLayout(ElmSharp.InputPanelLayout.Normal);
_editor.UpdateKeyboard(Element.Keyboard, Element.IsSpellCheckEnabled, Element.IsTextPredictionEnabled);

_editorPopup.BackButtonPressed += (s, e) => HidePopup();

Expand All @@ -99,16 +115,27 @@ void CreatePopup()
layout.SetPartContent("elm.swallow.content", _editor);
}

void PopupEntryTextChanged(object sender, TextChangedEventArgs e)
{
Control.Text = e.NewTextValue;
}

void PopupEntryActivated(object sender, EventArgs e)
{
((IEntryController)Element).SendCompleted();
}

void HidePopup()
{
Control.Text = _editor.Text;
if (_IMEState != Interop.EFL.InputPanelState.Hide)
{
_editor.HideInputPanel();
}
else if (_IMEState == Interop.EFL.InputPanelState.Hide)
{
_editorPopup.Hide();
_editor.TextChanged -= PopupEntryTextChanged;
_editor.Activated -= PopupEntryActivated;
}
}

Expand All @@ -118,20 +145,15 @@ void ShowPopup()
{
CreatePopup();
}
if (_editor.IsPassword != Control.IsPassword)
{
_editor.IsPassword = Control.IsPassword;
}

if (_editor.HorizontalTextAlignment != Control.HorizontalTextAlignment)
{
_editor.HorizontalTextAlignment = Control.HorizontalTextAlignment;
}
_editor.IsPassword = Control.IsPassword;
_editor.HorizontalTextAlignment = Control.HorizontalTextAlignment;

_editor.Text = Control.Text;
_editor.TextChanged += PopupEntryTextChanged;
_editor.Activated += PopupEntryActivated;

DefaultColor = new ElmSharp.Color(40, 40, 40, 255); //editfield bg default color
_editor.TextColor = Control.TextColor;
_editor.TextStyle = Control.TextStyle;
_editorPopup.Color = Control.BackgroundColor == default(ElmSharp.Color) ? DefaultColor : Control.BackgroundColor;

_editor.MoveCursorEnd();
Expand Down
7 changes: 7 additions & 0 deletions test/WearableUIGallery/WearableUIGallery/TC/TCPopupEntry.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
BackgroundColor="Gray"
HorizontalOptions="FillAndExpand"
TextColor="Blue"
Placeholder="Foobar"
PlaceholderColor="Blue"
VerticalOptions="CenterAndExpand" />
<w:PopupEntry
HorizontalOptions="FillAndExpand"
Expand All @@ -26,6 +28,11 @@
HorizontalOptions="FillAndExpand"
VerticalOptions="CenterAndExpand"
HorizontalTextAlignment="Center"/>
<w:PopupEntry
HorizontalOptions="FillAndExpand"
VerticalOptions="CenterAndExpand"
Keyboard="Numeric"
HorizontalTextAlignment="Center"/>
</StackLayout>
</w:CircleScrollView>
</ContentPage.Content>
Expand Down

0 comments on commit e9a588f

Please sign in to comment.