bool CanScrollUp(AView?view) { if (!(view is ViewGroup viewGroup)) { return(base.CanChildScrollUp()); } if (!CanScrollUpViewByType(view)) { return(false); } for (int i = 0; i < viewGroup.ChildCount; i++) { var child = viewGroup.GetChildAt(i); if (!CanScrollUpViewByType(child)) { return(false); } if (child is SwipeRefreshLayout) { return(CanScrollUp(child as ViewGroup)); } } return(true); }
void PropagateParentTouch() { if (_contentView == null) { return; } AView?itemContentView = null; var parentFound = _contentView.Parent.FindParent(parent => { if (parent is RecyclerView) { return(true); } itemContentView = parent as AView; return(false); }); if (parentFound != null) { itemContentView?.CallOnClick(); } }
bool CanScrollUpViewByType(AView?view) { if (view is AbsListView absListView) { if (absListView.FirstVisiblePosition == 0) { var subChild = absListView.GetChildAt(0); return(subChild != null && subChild.Top != 0); } return(true); } if (view is RecyclerView recyclerView) { return(recyclerView.ComputeVerticalScrollOffset() > 0); } if (view is NestedScrollView nestedScrollView) { return(nestedScrollView.ComputeVerticalScrollOffset() > 0); } if (view is AWebView webView) { return(webView.ScrollY > 0); } return(true); }
internal static IEnumerable <T> GetChildrenOfType <T>(this AViewGroup self) where T : AView { for (int i = 0; i < self.ChildCount; i++) { AView?child = self.GetChildAt(i); if (child == null) { continue; } if (child is T typedChild) { yield return(typedChild); } if (child is AViewGroup childAsViewGroup) { IEnumerable <T> myChildren = childAsViewGroup.GetChildrenOfType <T>(); foreach (T nextChild in myChildren) { yield return(nextChild); } } } }
protected override void OnAttached() { if (View == null) { return; } effect = TouchEffect.PickFrom(Element); if (effect?.IsDisabled ?? true) { return; } effect.Element = (VisualElement)Element; View.Touch += OnTouch; UpdateClickHandler(); accessibilityManager = View.Context?.GetSystemService(Context.AccessibilityService) as AccessibilityManager; if (accessibilityManager != null) { accessibilityListener = new AccessibilityListener(this); accessibilityManager.AddAccessibilityStateChangeListener(accessibilityListener); accessibilityManager.AddTouchExplorationStateChangeListener(accessibilityListener); } if (XCT.SdkInt < (int)BuildVersionCodes.Lollipop || !effect.NativeAnimation) { return; } View.Clickable = true; View.LongClickable = true; CreateRipple(); if (Group == null) { if (XCT.SdkInt >= (int)BuildVersionCodes.M) { View.Foreground = ripple; } return; } rippleView = new FrameLayout(Group.Context ?? throw new NullReferenceException()) { LayoutParameters = new ViewGroup.LayoutParams(-1, -1), Clickable = false, Focusable = false, Enabled = false, }; View.LayoutChange += OnLayoutChange; rippleView.Background = ripple; Group.AddView(rippleView); rippleView.BringToFront(); }
public void UpdateContent(IView?content, IMauiContext?mauiContext) { _contentView?.RemoveFromParent(); if (content != null && mauiContext != null) { _contentView = content.ToPlatform(mauiContext); var layoutParams = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); AddView(_contentView, layoutParams); } }
static void UpdateBackground(AView?control, VisualElement?element) { if (element == null || control == null) { return; } var background = element.Background; control.UpdateBackground(background); }
public override AView GetView(int position, AView?convertView, ViewGroup?parent) { convertView ??= new PickerInnerView(_Context, this); if (convertView is not PickerInnerView view) { return(convertView); } view.UpdateCell(_PickerCell.DisplayValue(_Source[position]), _PickerCell.SubDisplayValue(_Source[position])); return(view); }
void UpdateIndicatorTemplate(ILayout?layout) { if (layout == null || _indicatorView?.Handler?.MauiContext == null) { return; } AView?handler = layout.ToNative(_indicatorView.Handler.MauiContext); RemoveAllViews(); AddView(handler); }
protected override void OnAttached() { view = Control ?? Container; SetUpRipple(view); if (IsClickable) { view.Touch += OnViewTouch; } UpdateEffectColor(); }
protected override void OnDetached() { if (effect?.Element == null) { return; } try { if (accessibilityManager != null && accessibilityListener != null) { accessibilityManager.RemoveAccessibilityStateChangeListener(accessibilityListener); accessibilityManager.RemoveTouchExplorationStateChangeListener(accessibilityListener); accessibilityListener.Dispose(); accessibilityManager = null; accessibilityListener = null; } if (View != null) { View.LayoutChange -= OnLayoutChange; View.Touch -= OnTouch; View.Click -= OnClick; if (XCT.SdkInt >= (int)BuildVersionCodes.M && View.Foreground == ripple) { View.Foreground = null; } } effect.Element = null; effect = null; if (rippleView != null) { rippleView.Pressed = false; rippleView.Background = null; Group?.RemoveView(rippleView); rippleView.Dispose(); rippleView = null; } ripple?.Dispose(); ripple = null; } catch (ObjectDisposedException) { // Suppress exception } isHoverSupported = false; }
bool OnTouch(IButton? button, AView? v, MotionEvent? e) { switch (e?.ActionMasked) { case MotionEventActions.Down: button?.Pressed(); break; case MotionEventActions.Up: button?.Released(); break; } return false; }
internal void Connect(IView view, IMauiContext?mauiContext = null) { mauiContext = mauiContext ?? _mauiContext; var containerView = view.ToContainerView(mauiContext); var navigationLayout = containerView.FindViewById(Resource.Id.navigation_layout); if (containerView is DrawerLayout dl) { _rootView = dl; DrawerLayout = dl; } else if (containerView is ContainerView cv && cv.MainView is DrawerLayout dlc) { _rootView = cv; DrawerLayout = dlc; }
static void UpdateBackgroundColor(AView?control, VisualElement?element, Color?color = null) { if (element == null || control == null) { return; } var finalColor = color ?? element.BackgroundColor; if (finalColor.IsDefault) { control.SetBackground(null); } else { control.SetBackgroundColor(finalColor.ToAndroid()); } }
bool ShouldInterceptScrollChildrenTouch(ViewGroup scrollView, bool isHorizontal) { AView?scrollViewContent = scrollView.GetChildAt(0); if (scrollViewContent != null) { if (isHorizontal) { return(scrollView.ScrollX == 0 || scrollView.Width == scrollViewContent.Width + scrollView.PaddingLeft + scrollView.PaddingRight); } else { return(scrollView.ScrollY == 0 || scrollView.Height == scrollViewContent.Height + scrollView.PaddingTop + scrollView.PaddingBottom); } } return(true); }
protected override void OnDetached() { if (effect?.Element == null) { return; } try { if (accessibilityManager != null && accessibilityListener != null) { accessibilityManager.RemoveAccessibilityStateChangeListener(accessibilityListener); accessibilityManager.RemoveTouchExplorationStateChangeListener(accessibilityListener); accessibilityListener.Dispose(); accessibilityManager = null; accessibilityListener = null; } RemoveRipple(); if (View != null) { View.LayoutChange -= OnLayoutChange; View.Touch -= OnTouch; View.Click -= OnClick; } effect.Element = null; effect = null; if (rippleView != null) { rippleView.Pressed = false; Group?.RemoveView(rippleView); rippleView.Dispose(); rippleView = null; } } catch (ObjectDisposedException) { // Suppress exception } isHoverSupported = false; }
internal void SetRootView(IView view, IMauiContext?mauiContext = null) { mauiContext = mauiContext ?? _mauiContext; var containerView = view.ToContainerView(mauiContext); _navigationLayout = containerView.FindViewById(Resource.Id.navigation_layout); _navigationLayout ??= LayoutInflater .Inflate(Resource.Layout.navigationlayout, null) .JavaCast <CoordinatorLayout>(); if (containerView is DrawerLayout dl) { _rootView = dl; DrawerLayout = dl; } else if (containerView is ContainerView cv && cv.MainView is DrawerLayout dlc) { _rootView = cv; DrawerLayout = dlc; }
internal void UpdateContent() { if (_contentView != null) { _contentView.RemoveFromParent(); _contentView.Dispose(); _contentView = null; } if (Element?.PresentedContent is IView view) { _contentView = view.ToPlatform(MauiContext); } else { _contentView = CreateEmptyContent(); } AddView(_contentView); }
public void OnClick(AView?view) { if (!(view?.Tag is StepperHandlerHolder HandlerHolder)) { return; } if (!(HandlerHolder.StepperHandler?.VirtualView is IStepper stepper)) { return; } var increment = stepper.Interval; if (view == HandlerHolder.StepperHandler.DownButton) { increment = -increment; } HandlerHolder.StepperHandler.VirtualView.Value = stepper.Value + increment; UpdateButtons(HandlerHolder.StepperHandler.VirtualView, HandlerHolder.StepperHandler.DownButton, HandlerHolder.StepperHandler.UpButton); }
public void OnItemClick(AdapterView?parent, AView?view, int position, long id) { if (_ListView.ChoiceMode == ChoiceMode.Single || _PickerCell.IsSingleMode) { DoPickToClose(); return; } if (_PickerCell.IsValidMode && !_PickerCell.IsUnLimited && _ListView.CheckedItemCount > _PickerCell.MaxSelectedNumber) { _ListView.SetItemChecked(position, false); return; } DoPickToClose(); }
public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var context = (container.Context as StackNavigationManager.StackContext) ?? (container.Parent as AView)?.Context as StackNavigationManager.StackContext ?? throw new InvalidOperationException($"StackNavigationManager.StackContext not found"); _navigationManager = context.StackNavigationManager; _fragmentContainerView ??= (FragmentContainerView)container; // When shuffling around the back stack sometimes we'll need a page to detach and then reattach. // This mainly happens when users are removing or inserting pages. If we only have one page // and the user inserts a page at index zero we push a page onto the native backstack so // that we can get a toolbar with a back button. // Internally Android destroys the first fragment and then creates a second fragment. // Android removes the view associated with the first fragment and then adds the view // now associated with the second fragment. In our case this is the same view. // This is all a bit silly because the page is just getting added and removed to the same // view. Unfortunately FragmentContainerView is sealed so we can't inherit from it and influence // when the views are being added and removed. If this ends up causing too much shake up // Then we can try some other approachs like just modifying the navbar ourselves to include a back button // Even if there's only one page on the stack _currentView = NavigationManager.CurrentPage.Handler?.PlatformView as AView; if (_currentView == null) { var scopedContext = NavigationManager.MauiContext.MakeScoped(inflater, ChildFragmentManager); _currentView = NavigationManager.CurrentPage.ToPlatform(scopedContext); } _currentView.RemoveFromParent(); return(_currentView); }
protected override void OnDetached() { if (!IsClickable) { if (view != null) { view.Touch -= OnOverlayTouch; view.RemoveOnLayoutChangeListener(fastListener); } if (fastListener != null) { fastListener.Dispose(); fastListener = null; } if (rippleOverlay != null) { rippleOverlay.Dispose(); rippleOverlay = null; } } else { if (view != null) { view.Touch -= OnViewTouch; view.Background = orgDrawable; } orgDrawable = null; } ripple?.Dispose(); ripple = null; view = null; }
public static T?GetFirstChildOfType <T>(this AViewGroup viewGroup) where T : AView { for (var i = 0; i < viewGroup.ChildCount; i++) { AView?child = viewGroup.GetChildAt(i); if (child is T typedChild) { return(typedChild); } if (child is AViewGroup vg) { var descendant = vg.GetFirstChildOfType <T>(); if (descendant != null) { return(descendant); } } } return(null); }
public static IEnumerable <T> GetChildrenOfType <T>(this AViewGroup viewGroup) where T : AView { for (var i = 0; i < viewGroup.ChildCount; i++) { AView?child = viewGroup.GetChildAt(i); if (child is T typedChild) { yield return(typedChild); } if (child is AViewGroup) { IEnumerable <T>?myChildren = (child as AViewGroup)?.GetChildrenOfType <T>(); if (myChildren != null) { foreach (T nextChild in myChildren) { yield return(nextChild); } } } } }
public bool OnTouch(AView?v, global::Android.Views.MotionEvent?e) => Handler?.OnTouch(Handler?.VirtualView, v, e) ?? false;
public override void GetOutline(AView?view, Outline?outline) => outline?.SetRoundRect((int)offsetX, (int)offsetY, view?.Width ?? 0, view?.Height ?? 0, cornerRadius);
public void OnClick(AView?v) { Run(); }
public void OnClick(IButton?button, AView?v) { button?.Clicked(); }
public void OnClick(AView?v) { Handler?.OnClick(Handler?.VirtualView, v); }
public void OnClick(AView?v) { _command?.Invoke(v); }