-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSettingKeys.m
210 lines (176 loc) · 7.71 KB
/
SettingKeys.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//
// SettingKeys.m
// LNPopupSettings
//
// Created by Léo Natan on 2023-12-15.
// Copyright © 2023-2024 Léo Natan. All rights reserved.
//
#import "SettingKeys.h"
#import <LNTouchVisualizer/LNTouchVisualizer.h>
@import ObjectiveC;
PopupSetting const PopupSettingBarStyle = @"PopupSettingsBarStyle";
PopupSetting const PopupSettingInteractionStyle = @"PopupSettingsInteractionStyle";
PopupSetting const PopupSettingProgressViewStyle = @"PopupSettingsProgressViewStyle";
PopupSetting const PopupSettingCloseButtonStyle = @"PopupSettingsCloseButtonStyle";
PopupSetting const PopupSettingMarqueeEnabled = @"PopupSettingsMarqueeEnabled";
PopupSetting const PopupSettingMarqueeCoordinationEnabled = @"PopupSettingMarqueeCoordinationEnabled";
PopupSetting const PopupSettingHapticFeedbackEnabled = @"PopupSettingsHapticFeedbackEnabled";
PopupSetting const PopupSettingEnableCustomizations = @"PopupSettingsEnableCustomizations";
PopupSetting const PopupSettingExtendBar = @"PopupSettingsExtendBar";
PopupSetting const PopupSettingHidesBottomBarWhenPushed = @"PopupSettingsHidesBottomBarWhenPushed";
PopupSetting const PopupSettingDisableScrollEdgeAppearance = @"PopupSettingsDisableScrollEdgeAppearance";
PopupSetting const PopupSettingVisualEffectViewBlurEffect = @"PopupSettingsVisualEffectViewBlurEffect";
PopupSetting const PopupSettingTouchVisualizerEnabled = @"PopupSettingsTouchVisualizerEnabled";
PopupSetting const PopupSettingCustomBarEverywhereEnabled = @"PopupSettingsCustomBarEverywhereEnabled";
PopupSetting const PopupSettingContextMenuEnabled = @"PopupSettingsContextMenuEnabled";
PopupSetting const PopupSettingLimitFloatingWidth = @"PopupSettingLimitFloatingWidth";
PopupSetting const PopupSettingTabBarHasSidebar = @"PopupSettingTabBarHasSidebar";
PopupSetting const PopupSettingBarHideContentView = @"__LNPopupBarHideContentView";
PopupSetting const PopupSettingBarHideShadow = @"__LNPopupBarHideShadow";
PopupSetting const PopupSettingBarEnableLayoutDebug = @"__LNPopupBarEnableLayoutDebug";
PopupSetting const PopupSettingForceRTL = @"__LNForceRTL";
PopupSetting const PopupSettingDebugScaling = @"__LNDebugScaling";
PopupSetting const PopupSettingDisableDemoSceneColors = @"__LNPopupBarDisableDemoSceneColors";
PopupSetting const PopupSettingEnableFunkyInheritedFont = @"DemoAppEnableFunkyInheritedFont";
PopupSetting const PopupSettingEnableExternalScenes = @"DemoAppEnableExternalScenes";
PopupSetting const PopupSettingEnableCustomLabels = @"DemoAppEnableCustomLabels";
PopupSetting const PopupSettingUseScrollingPopupContent = @"PopupSettingUseScrollingPopupContent";
@implementation NSUserDefaults (LNPopupSettings)
+ (NSUserDefaults*)settingDefaults
{
static NSUserDefaults* rv = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
rv = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.LeoNatan.LNPopupSettings"];
[rv registerDefaults:@{
PopupSettingLimitFloatingWidth: @YES,
PopupSettingHidesBottomBarWhenPushed: @YES,
PopupSettingExtendBar: @YES,
PopupSettingHapticFeedbackEnabled: @YES,
PopupSettingMarqueeCoordinationEnabled: @YES,
PopupSettingTabBarHasSidebar: @YES
}];
});
return rv;
}
@end
__attribute__((constructor))
void fixUIKitSwiftUIShit(void)
{
[NSUserDefaults.standardUserDefaults removeObjectForKey:@"com.apple.SwiftUI.DisableCollectionViewBackedGroupedLists"];
[NSUserDefaults.standardUserDefaults registerDefaults:@{@"com.apple.SwiftUI.DisableCollectionViewBackedGroupedLists": @YES}];
{
Class cls = UICollectionViewCell.class;
void (*orig)(id, SEL, BOOL, BOOL);
SEL sel = NSSelectorFromString(@"_setHighlighted:animated:");
Method m = class_getInstanceMethod(cls, sel);
orig = (void*)method_getImplementation(m);
method_setImplementation(m, imp_implementationWithBlock(^(UICollectionViewCell* _self,
BOOL highlighted,
BOOL animated) {
if(highlighted == NO && [NSStringFromClass(_self.class) hasPrefix:@"SwiftUI."])
{
animated = YES;
}
orig(_self, sel, highlighted, animated);
}));
}
{
if(@available(iOS 17, *))
{
Class cls = NSClassFromString(@"UITabBarItem");
SEL sel = NSSelectorFromString(@"setScrollEdgeAppearance:");
void (*orig)(id, SEL, UITabBarAppearance*);
Method m = class_getInstanceMethod(cls, sel);
orig = (void*)method_getImplementation(m);
method_setImplementation(m, imp_implementationWithBlock(^(id _self, UITabBarAppearance* appearance) {
if([[appearance.class valueForKey:@"isFromSwiftUI"] boolValue] && appearance.backgroundEffect == nil && appearance.backgroundColor == nil && appearance.backgroundImage == nil)
{
appearance = nil;
}
orig(_self, sel, appearance);
}));
}
}
}
@interface LNTouchVisualizerSupport: NSObject @end
@implementation LNTouchVisualizerSupport
+ (void)load
{
@autoreleasepool
{
[NSUserDefaults.settingDefaults addObserver:(id)self forKeyPath:PopupSettingTouchVisualizerEnabled options:0 context:NULL];
[NSUserDefaults.settingDefaults addObserver:(id)self forKeyPath:PopupSettingDebugScaling options:0 context:NULL];
[NSNotificationCenter.defaultCenter addObserverForName:UISceneWillConnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) {
dispatch_async(dispatch_get_main_queue(), ^{
[self _updateTouchVisualizer];
[self _updateScalingAnimated:NO];
});
}];
}
}
+ (void)_updateTouchVisualizer
{
for(UIWindowScene* windowScene in UIApplication.sharedApplication.connectedScenes)
{
if([windowScene isKindOfClass:UIWindowScene.class] == NO)
{
continue;
}
windowScene.touchVisualizerEnabled = [NSUserDefaults.settingDefaults boolForKey:PopupSettingTouchVisualizerEnabled];
LNTouchConfig* rippleConfig = [LNTouchConfig rippleConfig];
rippleConfig.fillColor = UIColor.systemPinkColor;
windowScene.touchVisualizerWindow.touchRippleConfig = rippleConfig;
}
}
+ (void)_updateScalingAnimated:(BOOL)animated
{
for(UIWindowScene* windowScene in UIApplication.sharedApplication.connectedScenes)
{
if([windowScene isKindOfClass:UIWindowScene.class] == NO)
{
continue;
}
CGFloat desiredWidth = [NSUserDefaults.settingDefaults doubleForKey:PopupSettingDebugScaling];
if(desiredWidth == 0)
{
desiredWidth = windowScene.screen.fixedCoordinateSpace.bounds.size.width;
}
CGFloat scale = windowScene.screen.fixedCoordinateSpace.bounds.size.width / desiredWidth;
for(UIWindow* window in windowScene.windows)
{
window.layer.allowsEdgeAntialiasing = YES;
window.layer.magnificationFilter = kCAFilterTrilinear;
window.layer.minificationFilter = kCAFilterTrilinear;
CGAffineTransform targetTransform = scale == 1.0 ? CGAffineTransformIdentity : CGAffineTransformMakeScale(scale, scale);
CGRect targetFrame = windowScene.screen.bounds;
if(CGAffineTransformEqualToTransform(window.transform, targetTransform) == NO)
{
dispatch_block_t update = ^ {
[UIView performWithoutAnimation:^{
window.transform = targetTransform;
window.frame = targetFrame;
}];
};
if(animated == NO)
{
update();
return;
}
[UIView transitionWithView:window duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:update completion:nil];
}
}
}
}
+ (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
{
[self _updateTouchVisualizer];
[self _updateScalingAnimated:YES];
}
@end
@implementation NSNotificationCenter (LNPopupSettings)
- (id<NSObject>)addMainQueueObserverForName:(nullable NSNotificationName)name object:(nullable id)obj usingBlock:(void (^)(NSNotification * _Nonnull))block
{
return [self addObserverForName:name object:obj queue:NSOperationQueue.mainQueue usingBlock:block];
}
@end