diff --git a/AsyncDisplayKit.xcodeproj/project.pbxproj b/AsyncDisplayKit.xcodeproj/project.pbxproj index 4ce8706e6..5aad7bb9e 100644 --- a/AsyncDisplayKit.xcodeproj/project.pbxproj +++ b/AsyncDisplayKit.xcodeproj/project.pbxproj @@ -2609,6 +2609,9 @@ GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", + "AS_USE_ASSETS_LIBRARY=1", + "AS_USE_MAPKIT=1", + "AS_USE_PHOTOS=1", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; diff --git a/CHANGELOG.md b/CHANGELOG.md index c4d911575..9cc17d1c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - Fix misleading/scary stack trace shown when an assertion occurs during node measurement [Huy Nguyen](https://github.com/nguyenhuy) [#1022](https://github.com/TextureGroup/Texture/pull/1022) - Fix build on 32-bit simulator in Xcode 9.3 and later, caused by `Thread-local storage is not supported on this architecture.` [Adlai Holler](https://github.com/Adlai-Holler) - Enable locking assertions (and add some more) to improve and enforce locking safety within the framework [Huy Nguyen](https://github.com/nguyenhuy) [#1024](https://github.com/TextureGroup/Texture/pull/1024) +- Split MapKit, Photos, and AssetsLibrary dependent code into separate subspecs to improve binary size and start time when they're not needed. The default subspec includes all three for backwards compatibility, but this **will change in 3.0**. When using non-Cocoapods build environments, define `AS_USE_PHOTOS, AS_USE_MAPKIT, AS_USE_ASSETS_LIBRARY` to 1 respectively to signal their use. [Adlai Holler](https://github.com/Adlai-Holler) ## 2.7 - Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877) diff --git a/Source/ASMapNode.h b/Source/ASMapNode.h index 10a913e8a..c8820a18a 100644 --- a/Source/ASMapNode.h +++ b/Source/ASMapNode.h @@ -15,8 +15,11 @@ // http://www.apache.org/licenses/LICENSE-2.0 // +#import +#import + +#if TARGET_OS_IOS && AS_USE_MAPKIT #import -#if TARGET_OS_IOS #import NS_ASSUME_NONNULL_BEGIN diff --git a/Source/ASMapNode.mm b/Source/ASMapNode.mm index 43d037f61..8dc921579 100644 --- a/Source/ASMapNode.mm +++ b/Source/ASMapNode.mm @@ -15,11 +15,10 @@ // http://www.apache.org/licenses/LICENSE-2.0 // -#import - -#if TARGET_OS_IOS #import +#if TARGET_OS_IOS && AS_USE_MAPKIT + #import #import @@ -448,4 +447,4 @@ - (BOOL)supportsLayerBacking } @end -#endif +#endif // TARGET_OS_IOS && AS_USE_MAPKIT diff --git a/Source/ASMultiplexImageNode.mm b/Source/ASMultiplexImageNode.mm index aa335e793..1bddadb7d 100644 --- a/Source/ASMultiplexImageNode.mm +++ b/Source/ASMultiplexImageNode.mm @@ -17,7 +17,7 @@ #import -#if TARGET_OS_IOS +#if TARGET_OS_IOS && AS_USE_ASSETS_LIBRARY #import #endif @@ -25,12 +25,15 @@ #import #import #import -#import #import #import #import #import +#if AS_USE_PHOTOS +#import +#endif + #if AS_PIN_REMOTE_IMAGE #import #else @@ -39,7 +42,9 @@ NSString *const ASMultiplexImageNodeErrorDomain = @"ASMultiplexImageNodeErrorDomain"; +#if AS_USE_ASSETS_LIBRARY static NSString *const kAssetsLibraryURLScheme = @"assets-library"; +#endif static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0}; @@ -133,7 +138,7 @@ - (void)_loadNextImage; */ - (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image))completionBlock; -#if TARGET_OS_IOS +#if TARGET_OS_IOS && AS_USE_ASSETS_LIBRARY /** @abstract Loads the image corresponding to the given assetURL from the device's Assets Library. @param imageIdentifier The identifier for the image to be loaded. May not be nil. @@ -143,6 +148,7 @@ - (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imag - (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL completion:(void (^)(UIImage *image, NSError *error))completionBlock; #endif +#if AS_USE_PHOTOS /** @abstract Loads the image corresponding to the given image request from the Photos framework. @param imageIdentifier The identifier for the image to be loaded. May not be nil. @@ -150,6 +156,7 @@ - (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL com @param completionBlock The block to be performed when the image has been loaded, if possible. May not be nil. */ - (void)_loadPHAssetWithRequest:(ASPhotosFrameworkImageRequest *)request identifier:(id)imageIdentifier completion:(void (^)(UIImage *image, NSError *error))completionBlock API_AVAILABLE(ios(8.0), tvos(10.0)); +#endif /** @abstract Downloads the image corresponding to the given imageIdentifier from the given URL. @@ -620,7 +627,7 @@ - (void)_loadNextImage return; } -#if TARGET_OS_IOS +#if TARGET_OS_IOS && AS_USE_ASSETS_LIBRARY // If it's an assets-library URL, we need to fetch it from the assets library. if ([[nextImageURL scheme] isEqualToString:kAssetsLibraryURLScheme]) { // Load the asset. @@ -633,6 +640,7 @@ - (void)_loadNextImage } #endif +#if AS_USE_PHOTOS if (AS_AVAILABLE_IOS_TVOS(9, 10)) { // Likewise, if it's a Photos asset, we need to fetch it accordingly. if (ASPhotosFrameworkImageRequest *request = [ASPhotosFrameworkImageRequest requestWithURL:nextImageURL]) { @@ -644,6 +652,7 @@ - (void)_loadNextImage return; } } +#endif // Otherwise, it's a web URL that we can download. // First, check the cache. @@ -677,7 +686,7 @@ - (void)_loadNextImage }]; }]; } -#if TARGET_OS_IOS +#if TARGET_OS_IOS && AS_USE_ASSETS_LIBRARY - (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL completion:(void (^)(UIImage *image, NSError *error))completionBlock { ASDisplayNodeAssertNotNil(imageIdentifier, @"imageIdentifier is required"); @@ -702,6 +711,8 @@ - (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL com #pragma clang diagnostic pop } #endif + +#if AS_USE_PHOTOS - (void)_loadPHAssetWithRequest:(ASPhotosFrameworkImageRequest *)request identifier:(id)imageIdentifier completion:(void (^)(UIImage *image, NSError *error))completionBlock { ASDisplayNodeAssertNotNil(imageIdentifier, @"imageIdentifier is required"); @@ -789,6 +800,7 @@ - (void)_loadPHAssetWithRequest:(ASPhotosFrameworkImageRequest *)request identif _phImageRequestOperation = newImageRequestOp; [phImageRequestQueue addOperation:newImageRequestOp]; } +#endif - (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image))completionBlock { @@ -892,6 +904,7 @@ - (void)_finishedLoadingImage:(UIImage *)image forIdentifier:(id)imageIdentifier @end +#if AS_USE_PHOTOS @implementation NSURL (ASPhotosFrameworkURLs) + (NSURL *)URLWithAssetLocalIdentifier:(NSString *)assetLocalIdentifier targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:(PHImageRequestOptions *)options NS_RETURNS_RETAINED @@ -904,3 +917,4 @@ + (NSURL *)URLWithAssetLocalIdentifier:(NSString *)assetLocalIdentifier targetSi } @end +#endif diff --git a/Source/Base/ASAvailability.h b/Source/Base/ASAvailability.h index 3cb4862f9..32efcbc0b 100644 --- a/Source/Base/ASAvailability.h +++ b/Source/Base/ASAvailability.h @@ -25,6 +25,18 @@ #define AS_TLS_AVAILABLE 1 #endif +#ifndef AS_USE_PHOTOS +# define AS_USE_PHOTOS 0 +#endif + +#ifndef AS_USE_MAPKIT +# define AS_USE_MAPKIT 0 +#endif + +#ifndef AS_USE_ASSETS_LIBRARY +# define AS_USE_ASSETS_LIBRARY 0 +#endif + #ifndef kCFCoreFoundationVersionNumber_iOS_10_0 #define kCFCoreFoundationVersionNumber_iOS_10_0 1348.00 #endif diff --git a/Source/Details/ASPhotosFrameworkImageRequest.h b/Source/Details/ASPhotosFrameworkImageRequest.h index d11992233..869f5e810 100644 --- a/Source/Details/ASPhotosFrameworkImageRequest.h +++ b/Source/Details/ASPhotosFrameworkImageRequest.h @@ -15,6 +15,10 @@ // http://www.apache.org/licenses/LICENSE-2.0 // +#import + +#if AS_USE_PHOTOS + #import #import #import @@ -73,3 +77,5 @@ API_AVAILABLE(ios(8.0), tvos(10.0)) @end NS_ASSUME_NONNULL_END + +#endif // AS_USE_PHOTOS diff --git a/Source/Details/ASPhotosFrameworkImageRequest.m b/Source/Details/ASPhotosFrameworkImageRequest.m index 14028ccb6..35487d535 100644 --- a/Source/Details/ASPhotosFrameworkImageRequest.m +++ b/Source/Details/ASPhotosFrameworkImageRequest.m @@ -16,6 +16,9 @@ // #import + +#if AS_USE_PHOTOS + #import NSString *const ASPhotosURLScheme = @"ph"; @@ -160,3 +163,5 @@ - (BOOL)isEqual:(id)object } @end + +#endif // AS_USE_PHOTOS diff --git a/Texture.podspec b/Texture.podspec index 6b87ba146..c8a5f2be3 100644 --- a/Texture.podspec +++ b/Texture.podspec @@ -11,55 +11,71 @@ Pod::Spec.new do |spec| spec.documentation_url = 'http://texturegroup.org/appledoc/' - spec.ios.weak_frameworks = 'AssetsLibrary' - spec.weak_frameworks = 'Photos','MapKit' - spec.ios.deployment_target = '9.0' spec.tvos.deployment_target = '9.0' # Subspecs spec.subspec 'Core' do |core| core.public_header_files = [ - 'Source/*.h', - 'Source/Details/**/*.h', - 'Source/Layout/**/*.h', - 'Source/Base/*.h', - 'Source/Debug/**/*.h', - 'Source/TextKit/ASTextNodeTypes.h', - 'Source/TextKit/ASTextKitComponents.h' + 'Source/*.h', + 'Source/Details/**/*.h', + 'Source/Layout/**/*.h', + 'Source/Base/*.h', + 'Source/Debug/**/*.h', + 'Source/TextKit/ASTextNodeTypes.h', + 'Source/TextKit/ASTextKitComponents.h' ] core.source_files = [ - 'Source/**/*.{h,m,mm}', - 'Base/*.{h,m}', + 'Source/**/*.{h,m,mm}', + 'Base/*.{h,m}', - # Most TextKit components are not public because the C++ content - # in the headers will cause build errors when using - # `use_frameworks!` on 0.39.0 & Swift 2.1. - # See https://github.com/facebook/AsyncDisplayKit/issues/1153 - 'Source/TextKit/*.h', + # Most TextKit components are not public because the C++ content + # in the headers will cause build errors when using + # `use_frameworks!` on 0.39.0 & Swift 2.1. + # See https://github.com/facebook/AsyncDisplayKit/issues/1153 + 'Source/TextKit/*.h', ] end spec.subspec 'PINRemoteImage' do |pin| - pin.dependency 'PINRemoteImage/iOS', '= 3.0.0-beta.13' - pin.dependency 'PINRemoteImage/PINCache' - pin.dependency 'Texture/Core' + pin.dependency 'PINRemoteImage/iOS', '= 3.0.0-beta.13' + pin.dependency 'PINRemoteImage/PINCache' + pin.dependency 'Texture/Core' end spec.subspec 'IGListKit' do |igl| - igl.dependency 'IGListKit', '~> 3.0' - igl.dependency 'Texture/Core' + igl.dependency 'IGListKit', '~> 3.0' + igl.dependency 'Texture/Core' end spec.subspec 'Yoga' do |yoga| - yoga.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) YOGA=1' } - yoga.dependency 'Yoga', '1.6.0' - yoga.dependency 'Texture/Core' + yoga.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) YOGA=1' } + yoga.dependency 'Yoga', '1.6.0' + yoga.dependency 'Texture/Core' + end + + spec.subspec 'MapKit' do |map| + map.frameworks = 'MapKit' + map.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) AS_USE_MAPKIT=1' } + map.dependency 'Texture/Core' + end + + spec.subspec 'Photos' do |photos| + photos.frameworks = 'Photos' + photos.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) AS_USE_PHOTOS=1' } + photos.dependency 'Texture/Core' + end + + spec.subspec 'AssetsLibrary' do |assetslib| + assetslib.frameworks = 'AssetsLibrary' + assetslib.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) AS_USE_ASSETS_LIBRARY=1' } + assetslib.dependency 'Texture/Core' end - # Include optional PINRemoteImage module - spec.default_subspec = 'PINRemoteImage' + # Include these by default for backwards compatibility. + # This will change in 3.0. + spec.default_subspecs = 'PINRemoteImage', 'MapKit', 'AssetsLibrary', 'Photos' spec.social_media_url = 'https://twitter.com/TextureiOS' spec.library = 'c++'