зеркало из https://github.com/DeGsoft/maui-linux.git
[Tizen] Refactor the GestureDetector (#2059)
This commit is contained in:
Родитель
e42bd62fb5
Коммит
1a00ac0b1d
|
@ -19,6 +19,8 @@ namespace Xamarin.Forms.Platform.Tizen
|
|||
double _longTapTime = 0;
|
||||
int _horizontalSwipeTime = 0;
|
||||
int _verticalSwipeTime = 0;
|
||||
bool _inputTransparent = false;
|
||||
bool _isEnabled = true;
|
||||
|
||||
View View => _renderer.Element as View;
|
||||
|
||||
|
@ -26,21 +28,33 @@ namespace Xamarin.Forms.Platform.Tizen
|
|||
{
|
||||
get
|
||||
{
|
||||
if (_gestureLayer != null)
|
||||
return _gestureLayer.IsEnabled;
|
||||
|
||||
return false;
|
||||
return _isEnabled;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_gestureLayer != null)
|
||||
_gestureLayer.IsEnabled = value;
|
||||
_isEnabled = value;
|
||||
UpdateGestureLayerEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
public bool InputTransparent
|
||||
{
|
||||
get
|
||||
{
|
||||
return _inputTransparent;
|
||||
}
|
||||
set
|
||||
{
|
||||
_inputTransparent = value;
|
||||
UpdateGestureLayerEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
public GestureDetector(IVisualElementRenderer renderer)
|
||||
{
|
||||
_renderer = renderer;
|
||||
_isEnabled = View.IsEnabled;
|
||||
_inputTransparent = View.InputTransparent;
|
||||
|
||||
(View.GestureRecognizers as ObservableCollection<IGestureRecognizer>).CollectionChanged += OnGestureRecognizerCollectionChanged;
|
||||
|
||||
|
@ -75,9 +89,18 @@ namespace Xamarin.Forms.Platform.Tizen
|
|||
_gestureLayer = null;
|
||||
Clear();
|
||||
};
|
||||
_gestureLayer.IsEnabled = _renderer.Element.IsEnabled;
|
||||
UpdateGestureLayerEnabled();
|
||||
}
|
||||
|
||||
void UpdateGestureLayerEnabled()
|
||||
{
|
||||
if (_gestureLayer != null)
|
||||
{
|
||||
_gestureLayer.IsEnabled = !_inputTransparent && _isEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AddGestures(IEnumerable<IGestureRecognizer> recognizers)
|
||||
{
|
||||
foreach (var item in recognizers)
|
||||
|
@ -457,12 +480,7 @@ namespace Xamarin.Forms.Platform.Tizen
|
|||
|
||||
GestureHandler CreateHandler(IGestureRecognizer recognizer)
|
||||
{
|
||||
var handlerType = Registrar.Registered.GetHandlerTypeForObject(recognizer);
|
||||
|
||||
if (handlerType != null)
|
||||
return (GestureHandler)Activator.CreateInstance(handlerType, recognizer);
|
||||
else
|
||||
return null;
|
||||
return Registrar.Registered.GetHandlerForObject<GestureHandler>(recognizer, recognizer);
|
||||
}
|
||||
|
||||
GestureHandler LookupHandler(IGestureRecognizer recognizer)
|
||||
|
|
|
@ -57,7 +57,6 @@ namespace Xamarin.Forms.Platform.Tizen
|
|||
{
|
||||
if (initialize && Element.InputTransparent == default(bool))
|
||||
{
|
||||
NativeView.RepeatEvents = Element.CascadeInputTransparent;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -67,23 +66,21 @@ namespace Xamarin.Forms.Platform.Tizen
|
|||
{
|
||||
//Ignore all events of both layout and it's chidren
|
||||
NativeView.PassEvents = true;
|
||||
GestureDetector.IsEnabled = Element.IsEnabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Ignore Layout's event only. Children's events should be allowded.
|
||||
NativeView.PassEvents = false;
|
||||
NativeView.RepeatEvents = true;
|
||||
GestureDetector.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Allow layout's events and children's events would be determined by CascadeInputParent.
|
||||
NativeView.PassEvents = false;
|
||||
NativeView.RepeatEvents = Element.CascadeInputTransparent;
|
||||
GestureDetector.IsEnabled = Element.IsEnabled;
|
||||
NativeView.RepeatEvents = false;
|
||||
}
|
||||
GestureDetector.InputTransparent = Element.InputTransparent;
|
||||
}
|
||||
|
||||
void OnLayoutUpdated(object sender, Native.LayoutEventArgs e)
|
||||
|
|
|
@ -33,16 +33,6 @@ namespace Xamarin.Forms.Platform.Tizen
|
|||
}
|
||||
}
|
||||
|
||||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnElementPropertyChanged(sender, e);
|
||||
|
||||
if (e.PropertyName == VisualElement.IsEnabledProperty.PropertyName)
|
||||
{
|
||||
UpdateIsEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native control associated with this renderer.
|
||||
/// </summary>
|
||||
|
@ -60,8 +50,9 @@ namespace Xamarin.Forms.Platform.Tizen
|
|||
SetNativeView(control);
|
||||
}
|
||||
|
||||
void UpdateIsEnabled()
|
||||
protected override void UpdateIsEnabled(bool initialize)
|
||||
{
|
||||
base.UpdateIsEnabled(initialize);
|
||||
_gestureDetector.Value.IsEnabled = Element.IsEnabled;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -766,7 +766,7 @@ namespace Xamarin.Forms.Platform.Tizen
|
|||
/// <summary>
|
||||
/// Updates the IsEnabled property.
|
||||
/// </summary>
|
||||
void UpdateIsEnabled(bool initialize)
|
||||
protected virtual void UpdateIsEnabled(bool initialize)
|
||||
{
|
||||
if (initialize && Element.IsEnabled)
|
||||
return;
|
||||
|
|
Загрузка…
Ссылка в новой задаче