This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow not to use UIImageAsset on iOS 13 (#88)
* Allow not to use UIImageAsset on iOS13 * Use imageWithConfiguration: on iOS 13+ * Add configuration class
- Loading branch information
1 parent
f94228e
commit 5883735
Showing
19 changed files
with
290 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface DMEnvironmentConfiguration : NSObject | ||
|
||
@property (nonatomic) BOOL useImageAsset; // Defaults to NO | ||
|
||
- (instancetype)init; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// | ||
|
||
#import "DMEnvironmentConfiguration.h" | ||
|
||
@implementation DMEnvironmentConfiguration | ||
|
||
- (instancetype)init { | ||
self = [super init]; | ||
if (self) { | ||
_useImageAsset = NO; | ||
} | ||
return self; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface UIImage (DarkModeKitSwizzling) | ||
|
||
@property (class, readonly) BOOL useUIImageAsset; | ||
|
||
+ (void)dm_swizzleIsEqual; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// | ||
|
||
#import "UIImage+DarkModeKitSwizzling.h" | ||
#import "DMDynamicImage.h" | ||
|
||
@import ObjectiveC; | ||
|
||
static BOOL _useUIImageAsset = YES; | ||
|
||
@implementation UIImage (DarkModeKitSwizzling) | ||
|
||
+ (BOOL)useUIImageAsset { | ||
return _useUIImageAsset; | ||
} | ||
|
||
+ (void)dm_swizzleIsEqual { | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
SEL selector = @selector(isEqual:); | ||
Method method = class_getInstanceMethod(self, selector); | ||
if (!method) | ||
NSAssert(NO, @"Method not found for [UIImage isEqual:]"); | ||
|
||
IMP imp = method_getImplementation(method); | ||
class_replaceMethod(self, selector, imp_implementationWithBlock(^BOOL(UIImage *self, UIImage *other) { | ||
/// On iOS 13, UIImage `isEqual:` somehow changes internally and doesn't work for `NSProxy`, | ||
/// here we forward the message to internal images manually | ||
UIImage *realSelf = self; | ||
UIImage *realOther = other; | ||
if (object_getClass(self) == DMDynamicImageProxy.class) { | ||
realSelf = ((DMDynamicImageProxy *)self).resolvedImage; | ||
} | ||
if (object_getClass(other) == DMDynamicImageProxy.class) { | ||
realOther = ((DMDynamicImageProxy *)other).resolvedImage; | ||
} | ||
return ((BOOL(*)(UIImage *, SEL, UIImage *))imp)(realSelf, selector, realOther); | ||
}), method_getTypeEncoding(method)); | ||
|
||
_useUIImageAsset = NO; | ||
}); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.