Răsfoiți Sursa

Fix xctl configure bug

xingcheng02 2 ani în urmă
părinte
comite
eb3436576c

+ 19 - 18
XCBaseContainer/Classes/MultiTab/View/XCBCCategorySelectView.m

@@ -5,10 +5,10 @@
 //  Created by 邢铖 on 2023/6/6.
 //
 
-#import "XCComCategorySelectView.h"
-#import <XCPublicModule/XCPublicModule.h>
+#import "XCBCCategorySelectView.h"
 #import <Masonry/Masonry.h>
-#import "OCUtils.h"
+
+#define clamp(t, min, max) ((min) + ((max) - (min)) * (t))
 
 static char kXCBCCategorySelectTitleViewKVOKey[] = "kXCBCCategorySelectTitleViewKVOKey";
 
@@ -44,22 +44,27 @@ static char kXCBCCategorySelectTitleViewKVOKey[] = "kXCBCCategorySelectTitleView
     }
 }
 
+- (UIColor *)makeColorWithDiff:(CGFloat)diff alpha:(CGFloat)alpha {
+    return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
+        if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
+            return [UIColor colorWithWhite:diff alpha:alpha];
+        } else {
+            return [UIColor colorWithWhite:1 - diff alpha:alpha];
+        }
+    }];
+}
+
 - (void)updateSelectable {
     CGFloat maximumSize = 20;
     CGFloat minimumSize = 15;
     UIFontWeight maximumWeight = UIFontWeightHeavy;
     UIFontWeight minimumWeight = UIFontWeightThin;
-#define clamp(t, min, max) ((min) + ((max) - (min)) * (t))
     NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:self.categoryTitle];
     NSRange allRange = NSMakeRange(0, attr.length);
     [attr setAttributes:@{
-        NSForegroundColorAttributeName : [UIColor grayScaleWithDiff:[self clampValue:self.selectPrecentage
-                                                                       withBoundLeft:0.4
-                                                                       andBoundRight:1]
-                                                              alpha:1]
+        NSForegroundColorAttributeName : [self makeColorWithDiff:clamp(self.selectPrecentage, 0.4, 1) alpha:1]
 //        NSFontAttributeName : [UIFont systemFontOfSize:clamp(self.selectPrecentage, minimumSize, maximumSize)]
     } range:allRange];
-#undef clamp
     [self setAttributedTitle:attr forState:UIControlStateNormal];
     [self layoutSubviews];
 }
@@ -119,7 +124,7 @@ static char kXCBCCategorySelectViewKVOKey[] = "kXCBCCategorySelectViewKVOKey";
 - (UIView *)indicatorView {
     if (!_indicatorView) {
         _indicatorView = [UIView new];
-        _indicatorView.backgroundColor = UIColor.systemOrangeColor;
+        _indicatorView.backgroundColor = UIColor.linkColor;
         _indicatorView.layer.masksToBounds = true;
         _indicatorView.layer.cornerRadius = 1.5;
     }
@@ -162,9 +167,9 @@ static char kXCBCCategorySelectViewKVOKey[] = "kXCBCCategorySelectViewKVOKey";
     for (NSString *categoryName in self.categoryNames) {
         XCBCCategorySelectTitleView *button = [XCBCCategorySelectTitleView new];
         button.categoryTitle = categoryName;
-        XC_WEAKIFY_SELF;
+        __weak typeof(self) weakSelf = self;
         button.touchBlock = ^{
-            XC_STRONG_SELF;
+            typeof(self) self = weakSelf;
             [self userDidSelectCategoryAtIndex:index];
         };
         [self.stackView addArrangedSubview:button];
@@ -196,12 +201,8 @@ static char kXCBCCategorySelectViewKVOKey[] = "kXCBCCategorySelectViewKVOKey";
             CGFloat leftRightPercentageValue = self.selectedIndex - leftObjectIndex;
             XCBCCategorySelectTitleView *leftView = self.stackView.arrangedSubviews[leftObjectIndex];
             XCBCCategorySelectTitleView *rightView = self.stackView.arrangedSubviews[rightObjectIndex];
-            CGFloat selectorWidth = [self clampValue:leftRightPercentageValue
-                                       withBoundLeft:leftView.frame.size.width
-                                       andBoundRight:rightView.frame.size.width];
-            CGFloat selectorLeft = [self clampValue:leftRightPercentageValue
-                                      withBoundLeft:leftView.frame.origin.x
-                                      andBoundRight:rightView.frame.origin.x];
+            CGFloat selectorWidth = clamp(leftRightPercentageValue, leftView.frame.size.width, rightView.frame.size.width);
+            CGFloat selectorLeft = clamp(leftRightPercentageValue, leftView.frame.origin.x, rightView.frame.origin.x);
             leftView.selectPrecentage = 1 - leftRightPercentageValue;
             rightView.selectPrecentage = leftRightPercentageValue;
             [self.indicatorView mas_remakeConstraints:^(MASConstraintMaker *make) {

+ 0 - 1
XCBaseContainer/Classes/MultiTab/XCBCMultiTabPageViewController.h

@@ -6,7 +6,6 @@
 //
 
 #import <UIKit/UIKit.h>
-#import <XCPublicModule/XCPublicModule.h>
 
 NS_ASSUME_NONNULL_BEGIN
 

+ 31 - 19
XCBaseContainer/Classes/MultiTab/XCBCMultiTabPageViewController.m

@@ -29,6 +29,7 @@ static char kXCComEntryTabPageViewControllerKVOKey[] = "kXCComEntryTabPageViewCo
            forKeyPath:@"managedViewControllers"
               options:NSKeyValueObservingOptionNew
               context:kXCComEntryTabPageViewControllerKVOKey];
+    [self view];
     return self;
 }
 
@@ -42,15 +43,15 @@ static char kXCComEntryTabPageViewControllerKVOKey[] = "kXCComEntryTabPageViewCo
 - (XCBCCategorySelectView *)categorySelectView {
     if (!_categorySelectView) {
         _categorySelectView = [XCBCCategorySelectView new];
-        XC_WEAKIFY_SELF;
+        __weak typeof(self) weakSelf = self;
         _categorySelectView.categoryClickedBlock = ^(NSInteger newIndex) {
-            XC_STRONG_SELF;
-            [self.categorySelectView animateChangingBlock:^(CGFloat value) {
-                self.categorySelectView.selectedIndex = value;
+            typeof(self) self = weakSelf;
+            [UIView animateWithDuration:0.38 animations:^{
+                self.categorySelectView.selectedIndex = newIndex;
                 CGPoint offset = self.scrollView.contentOffset;
-                offset.x = self.scrollView.frame.size.width * value;
+                offset.x = self.scrollView.frame.size.width * newIndex;
                 self.scrollView.contentOffset = offset;
-            } from:self.categorySelectView.selectedIndex to:newIndex forTime:0.38];
+            }];
         };
     }
     return _categorySelectView;
@@ -100,17 +101,26 @@ static char kXCComEntryTabPageViewControllerKVOKey[] = "kXCComEntryTabPageViewCo
 
 - (void)viewDidLoad {
     [self configureSubviews];
-    dispatch_async(dispatch_get_main_queue(), ^{
-        [super viewDidLoad]; // prepare for treelang
-    });
+    [super viewDidLoad];
+}
+
+static UIViewController *_Nullable findViewController(UIView *view) {
+    if ([view.nextResponder isKindOfClass:UIViewController.class]) {
+        return (UIViewController *)view.nextResponder;
+    }
+    UIView *superView = view.superview;
+    if (!superView) {
+        return nil;
+    }
+    return findViewController(superView);
 }
 
 - (void)configureScrollContents {
     for (UIView *view in self.stackView.arrangedSubviews) {
         [self.stackView removeArrangedSubview:view];
-        [view.viewController willMoveToParentViewController:nil];
+        [findViewController(view) willMoveToParentViewController:nil];
         [view removeFromSuperview];
-        [view.viewController removeFromParentViewController];
+        [findViewController(view) removeFromParentViewController];
     }
     for (UIViewController *controller in self.managedViewControllers) {
         [controller willMoveToParentViewController:self];
@@ -134,11 +144,13 @@ static char kXCComEntryTabPageViewControllerKVOKey[] = "kXCComEntryTabPageViewCo
             [titles addObject:controller.title];
         }
         self.categorySelectView.categoryNames = titles;
-        self.categorySelectView.selectedIndex = self.defaultSelectionIndex;
-        [self configureScrollContents];
-        CGPoint offset = self.scrollView.contentOffset;
-        offset.x = self.scrollView.frame.size.width * self.categorySelectView.selectedIndex;
-        self.scrollView.contentOffset = offset;
+        dispatch_async(dispatch_get_main_queue(), ^{
+            self.categorySelectView.selectedIndex = self.defaultSelectionIndex;
+            [self configureScrollContents];
+            CGPoint offset = self.scrollView.contentOffset;
+            offset.x = self.scrollView.frame.size.width * self.categorySelectView.selectedIndex;
+            self.scrollView.contentOffset = offset;
+        });
     } else {
         [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
     }
@@ -167,8 +179,6 @@ static char kXCComEntryTabPageViewControllerKVOKey[] = "kXCComEntryTabPageViewCo
                  context:kXCComEntryTabPageViewControllerKVOKey];
 }
 
-
-
 @end
 
 @interface XCBCMultiTabPageViewController (Scrolling)
@@ -203,7 +213,9 @@ static char kXCComEntryTabPageViewControllerKVOKey[] = "kXCComEntryTabPageViewCo
                                          userInfo:nil];
         }
     }
-    controller.managedViewControllers = arg;
+    dispatch_async(dispatch_get_main_queue(), ^{
+        controller.managedViewControllers = arg;
+    });
     return controller;
 }