Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望在 一级功能列表页面 添加功能入口,目前我使用运行时做到了,owner看看能不能后面作为原生功能。 #110

Open
lovivid opened this issue May 6, 2024 · 0 comments

Comments

@lovivid
Copy link

lovivid commented May 6, 2024

我希望在小圆点点击后的 一级功能列表页面 添加入口,如下图。

截屏2024-05-06 15 19 44

我没有找到原生方法,我看了下 原代码,使用runtime 方法做到了。如下描述。

1 of 3 使用运行时,为 LLConfig 增加额外的 属性

typedef void(^LLConfigFunctionListDidLoad)(UIViewController *);

@interface LLConfig (customAdd)
@property (nonatomic, copy) LLConfigFunctionListDidLoad flDidloadBlock;
@end


static char *YYFLBlockKey;
@implementation LLConfig (customAdd)

- (void)setFlDidloadBlock:(LLConfigFunctionListDidLoad)flBlock {
    if (flBlock){
        objc_setAssociatedObject(self, &YYFLBlockKey, flBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
    } else {
        objc_setAssociatedObject(self, &YYFLBlockKey, nil, OBJC_ASSOCIATION_COPY_NONATOMIC);
    }
}

- (LLConfigFunctionListDidLoad)flDidloadBlock {
    id rtnBlock = objc_getAssociatedObject(self, &YYFLBlockKey);
    if (rtnBlock) {
        return rtnBlock;
    }
    return nil;
}
@end

2 of 3 使用运行时,在viewDidLoad 增加对于 LLConfig.flDidloadBlock 的调用

@interface LLFunctionViewController (customAdd)
@end

@implementation LLFunctionViewController (customAdd)

- (void)YY_viewDidLoad {
    // 方法交换后,YY_viewDidLoad 其实调用的是交换前的 viewDidLoad
    [self YY_viewDidLoad];
    
    // 检查 LLConfig.flDidloadBlock,如果存在,调用之
    if ([LLConfig shared].flDidloadBlock) {
        [LLConfig shared].flDidloadBlock(self);
    }
}

+ (void)load{
    // 使用魔法,在viewDidLoad 增加对于 LLConfig.flDidloadBlock 的调用
    Method originalMethod = class_getInstanceMethod(self, @selector(viewDidLoad));
    Method swizzledMethod = class_getInstanceMethod(self, @selector(YY_viewDidLoad));
    method_exchangeImplementations(originalMethod, swizzledMethod);
}

@end

3 of 3 在初始化的时候,使用新加的属性,在 一级功能页面增加入口

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
......
@weakify(self)
 [[LLDebugTool sharedTool] startWorkingWithConfigBlock:^(LLConfig * _Nonnull config) {
        @strongify(self);if (!self){return;}

        config.userIdentity = @"Miss L";

        config.logStyle = LLConfigLogNone;

        config.flDidloadBlock = ^(UIViewController * flVC) {
            @strongify(self);if (!self){return;}

            // UI构建 "lightMode"
            UILabel* lightMode =  ......
            [flVC.view addSubview:lightMode atLeft:160 atTop:350];
            
            // UI构建 "darkMode"
            UILabel* darkMode = ......
            [flVC.view addSubview:darkMode atLeft:lightMode.right+16 atTop:350];
            
            // 新增 UI 点击响应 逻辑
            [lightMode viewClick:^(UIView *viewClicked) {
                @strongify(self);if (!self){return;}
                [self changeRootWinDark:@"light"];
                
                // 动作逻辑完成后,关闭一级功能列表页面
                [[LLWindowManager shared] showEntryWindow];
            }];
            
            [darkMode viewClick:^(UIView *viewClicked) {
                @strongify(self);if (!self){return;}
                [self changeRootWinDark:@"dark"];

                 // 动作逻辑完成后,关闭一级功能列表页面
                [[LLWindowManager shared] showEntryWindow];
            }];
        };

    }];
......
}


- (void)changeRootWinDark:(NSString*)tobe {
// 修改 app 为 light or dark 模式
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant