diff --git a/NXKit/lib/Core/UILabel/UILabel.cpp b/NXKit/lib/Core/UILabel/UILabel.cpp index 0ceb4e4..3a8121b 100644 --- a/NXKit/lib/Core/UILabel/UILabel.cpp +++ b/NXKit/lib/Core/UILabel/UILabel.cpp @@ -89,7 +89,7 @@ YGSize UILabel::labelMeasureFunc(YGNodeRef node, float width, YGMeasureMode widt } else { - // fatal("Unsupported Label width measure mode: " + std::to_string(widthMode)); + printf("Unsupported Label width measure mode: %s\n", std::to_string(widthMode).c_str()); } // Height @@ -138,7 +138,7 @@ YGSize UILabel::labelMeasureFunc(YGNodeRef node, float width, YGMeasureMode widt } else { - // fatal("Unsupported Label height measure mode: " + std::to_string(heightMode)); + printf("Unsupported Label height measure mode: %s\n", std::to_string(heightMode).c_str()); } } // No wrapping necessary or allowed, return the normal height diff --git a/NXKit/lib/Core/UIScrollView/UIScrollView.cpp b/NXKit/lib/Core/UIScrollView/UIScrollView.cpp index 5e0293b..35f0d94 100644 --- a/NXKit/lib/Core/UIScrollView/UIScrollView.cpp +++ b/NXKit/lib/Core/UIScrollView/UIScrollView.cpp @@ -183,7 +183,8 @@ void UIScrollView::layoutSubviews() { if (contentView) { Size frameSize = getBounds().size; - Size size = Size(fixWidth ? frameSize.width : UIView::AUTO, fixHeight ? frameSize.height : UIView::AUTO); + Size size = Size(fixWidth ? frameSize.width : UIView::AUTO, + fixHeight ? frameSize.height : UIView::AUTO); contentView->setSize(size); } diff --git a/NXKit/lib/Core/UISelectorViewController/UISelectorViewController.cpp b/NXKit/lib/Core/UISelectorViewController/UISelectorViewController.cpp index bd647f8..9fe89c2 100644 --- a/NXKit/lib/Core/UISelectorViewController/UISelectorViewController.cpp +++ b/NXKit/lib/Core/UISelectorViewController/UISelectorViewController.cpp @@ -32,13 +32,6 @@ void UISelectorViewController::loadView() { view->addSubview(makeFooter()); } -void UISelectorViewController::viewWillAppear(bool animated) { - if (selectedView) { - getView()->layoutIfNeeded(); - Application::shared()->setFocus(selectedView); - } -} - UIView* UISelectorViewController::makeContentView() { UINavigationBar* navigationBar = new UINavigationBar(); navigationBar->setSize(Size(UIView::AUTO, headerHeight)); @@ -125,8 +118,19 @@ void UISelectorViewController::viewDidLayoutSubviews() { float contHeight = contentView->getBounds().size.height; float height = std::min(heightLimit, contHeight); - if (!floatSame(scrollView->getBounds().size.height, height)) + if (!floatSame(scrollView->getBounds().size.height, height)) { scrollView->setHeight(height); + + if (selectedView) { + Application::shared()->setFocus(selectedView); + + Rect focusedViewFrame = selectedView->getFrame(); + Point origin = selectedView->getSuperview()->convert(focusedViewFrame.origin, scrollView); + origin.y -= height / 2 - focusedViewFrame.height() / 2; + + scrollView->setContentOffset(origin, true); + } + } } void UISelectorViewController::makeViewAppear(bool animated, UIViewController* presentingViewController, std::function completion) { diff --git a/NXKit/lib/Core/UISelectorViewController/UISelectorViewController.hpp b/NXKit/lib/Core/UISelectorViewController/UISelectorViewController.hpp index 0b2ff82..4fcc5e1 100644 --- a/NXKit/lib/Core/UISelectorViewController/UISelectorViewController.hpp +++ b/NXKit/lib/Core/UISelectorViewController/UISelectorViewController.hpp @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include @@ -19,7 +20,6 @@ public: UISelectorViewController(std::string title, std::vector data, std::function onComplete, int selectedIndex = -1); void loadView() override; - void viewWillAppear(bool animated) override; void viewDidLayoutSubviews() override; protected: @@ -30,7 +30,7 @@ private: float headerHeight = 70; float footerHeight = 73; - UIView* scrollView = nullptr; + UIScrollView* scrollView = nullptr; UIView* contentView = nullptr; UIView* containerView = nullptr; diff --git a/NXKit/lib/Core/UIView/UIView.cpp b/NXKit/lib/Core/UIView/UIView.cpp index 17ccf3f..d74d7b7 100644 --- a/NXKit/lib/Core/UIView/UIView.cpp +++ b/NXKit/lib/Core/UIView/UIView.cpp @@ -517,7 +517,7 @@ void UIView::applyAnimationContext(std::deque* context) { } void UIView::animate(float duration, std::function animations, EasingFunction easing, std::function completion) { - if (duration <= 0) { + if (duration <= 0 || noAnimations) { animations(); animationContext.reset(createAnimationContext()); completion(true); @@ -879,6 +879,13 @@ float UIView::getBorderBottom() { } void UIView::animate(std::initializer_list views, float duration, std::function animations, EasingFunction easing, std::function completion) { + // Maybe needs improvements + if (noAnimations) { + animations(); + completion(true); + return; + } + if (duration <= 0) { animations(); for (UIView* view: views) { @@ -925,6 +932,15 @@ void UIView::animate(std::initializer_list views, float duration, std:: } } +bool UIView::noAnimations = false; + +void UIView::performWithoutAnimation(std::function function) { + bool old = noAnimations; + noAnimations = true; + function(); + noAnimations = old; +} + // Trait collection UITraitCollection UIView::getTraitCollection() { if (controller) diff --git a/NXKit/lib/Core/UIView/UIView.hpp b/NXKit/lib/Core/UIView/UIView.hpp index ec794fc..7493850 100644 --- a/NXKit/lib/Core/UIView/UIView.hpp +++ b/NXKit/lib/Core/UIView/UIView.hpp @@ -96,6 +96,8 @@ public: virtual void applyAnimationContext(std::deque* context); void animate(float duration, std::function animations, EasingFunction easing = EasingFunction::linear, std::function completion = [](bool res){}); + static void performWithoutAnimation(std::function function); + void addGestureRecognizer(UIGestureRecognizer* gestureRecognizer); std::vector getGestureRecognizers(); @@ -174,6 +176,7 @@ private: friend class UIViewController; friend class UITableView; + static bool noAnimations; std::optional tintColor; AnimationContext animationContext;