Skip to content

Commit

Permalink
Add a -textureDidInitialize delegate callback (TextureGroup#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adlai-Holler authored and mikezucc committed Oct 2, 2018
1 parent e418861 commit 13536d6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- Optimize text stack by removing unneeded copying. [Adlai Holler](https://github.com/Adlai-Holler)
- Renamed `accessibleElements` to `accessibilityElements` and removed the re-definition of the property in ASDisplayView. [Jia Wern Lim](https://github.com/jiawernlim)
- Remove double scaling of lineHeightMultiple & paragraphSpacing attributes in ASTextKitFontSizeAdjuster. [Eric Jensen](https://github.com/ejensen)
- Add a delegate callback for when the framework has initialized. [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)
Expand Down
10 changes: 10 additions & 0 deletions Source/ASConfigurationDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)textureDidActivateExperimentalFeatures:(ASExperimentalFeatures)features;

@optional

/**
* Texture framework initialized. This method is called synchronously
* on the main thread from ASInitializeFrameworkMainThread if you defined
* AS_INITIALIZE_FRAMEWORK_MANUALLY or from the default initialization point
* (currently +load) otherwise.
*/
- (void)textureDidInitialize;

@end

NS_ASSUME_NONNULL_END
5 changes: 5 additions & 0 deletions Source/ASConfigurationInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
AS_EXTERN BOOL ASActivateExperimentalFeature(ASExperimentalFeatures option);

/**
* Notify the configuration delegate that the framework initialized, if needed.
*/
AS_EXTERN void ASNotifyInitialized(void);

AS_SUBCLASSING_RESTRICTED
@interface ASConfigurationManager : NSObject

Expand Down
22 changes: 22 additions & 0 deletions Source/ASConfigurationInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "ASConfigurationInternal.h"
#import <AsyncDisplayKit/ASAssert.h>
#import <AsyncDisplayKit/ASConfiguration.h>
#import <AsyncDisplayKit/ASConfigurationDelegate.h>
#import <stdatomic.h>
Expand All @@ -16,6 +17,7 @@
@implementation ASConfigurationManager {
ASConfiguration *_config;
dispatch_queue_t _delegateQueue;
BOOL _frameworkInitialized;
_Atomic(ASExperimentalFeatures) _activatedExperiments;
}

Expand Down Expand Up @@ -51,6 +53,21 @@ - (instancetype)init
return self;
}

- (void)frameworkDidInitialize
{
ASDisplayNodeAssertMainThread();
if (_frameworkInitialized) {
ASDisplayNodeFailAssert(@"Framework initialized twice.");
return;
}
_frameworkInitialized = YES;

let delegate = _config.delegate;
if ([delegate respondsToSelector:@selector(textureDidInitialize)]) {
[delegate textureDidInitialize];
}
}

- (BOOL)activateExperimentalFeature:(ASExperimentalFeatures)requested
{
if (_config == nil) {
Expand Down Expand Up @@ -90,3 +107,8 @@ BOOL ASActivateExperimentalFeature(ASExperimentalFeatures feature)
{
return [ASGetSharedConfigMgr() activateExperimentalFeature:feature];
}

void ASNotifyInitialized()
{
[ASGetSharedConfigMgr() frameworkDidInitialize];
}
2 changes: 2 additions & 0 deletions Source/Private/ASInternalHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import <objc/runtime.h>
#import <tgmath.h>

#import <AsyncDisplayKit/ASConfigurationInternal.h>
#import <AsyncDisplayKit/ASRunLoopQueue.h>
#import <AsyncDisplayKit/ASThread.h>

Expand Down Expand Up @@ -53,6 +54,7 @@ void ASInitializeFrameworkMainThread(void)
allowsGroupOpacityFromUIKitOrNil = @(layer.allowsGroupOpacity);
allowsEdgeAntialiasingFromUIKitOrNil = @(layer.allowsEdgeAntialiasing);
}
ASNotifyInitialized();
}

BOOL ASSubclassOverridesSelector(Class superclass, Class subclass, SEL selector)
Expand Down

0 comments on commit 13536d6

Please sign in to comment.