Skip to content

Commit

Permalink
chore(ios): eliminate warnings and optimize code (#3798)
Browse files Browse the repository at this point in the history
* chore(ios): eliminate warnings and optimize code

* chore(ios): clean up obsolete functions
  • Loading branch information
wwwcg authored Mar 28, 2024
1 parent e841936 commit c39dc12
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 48 deletions.
39 changes: 14 additions & 25 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ - (void)unregisterRootViewFromTag:(NSNumber *)rootTag {
userInfo:userInfo];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<NSKeyValueChangeKey,id> *)change
context:(void *)context {
if ([keyPath isEqualToString:@"frame"] && [object isKindOfClass:[UIView class]]) {
CGRect curFrame = [change[NSKeyValueChangeNewKey] CGRectValue];
CGRect oriFrame = [change[NSKeyValueChangeOldKey] CGRectValue];
Expand Down Expand Up @@ -705,19 +708,6 @@ - (void)addUIBlock:(HippyViewManagerUIBlock)block {
[_pendingUIBlocks addObject:block];
}
- (void)amendPendingUIBlocksWithStylePropagationUpdateForRenderObject:(HippyShadowView *)topView {
NSMutableSet<NativeRenderApplierBlock> *applierBlocks = [NSMutableSet setWithCapacity:256];
[topView collectUpdatedProperties:applierBlocks parentProperties:@{}];
if (applierBlocks.count) {
[self addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
for (NativeRenderApplierBlock block in applierBlocks) {
block(viewRegistry, nil);
}
}];
}
}
- (void)flushUIBlocksOnRootNode:(std::weak_ptr<RootNode>)rootNode {
// First copy the previous blocks into a temporary variable, then reset the
// pending blocks to a new array. This guards against mutation while
Expand Down Expand Up @@ -762,7 +752,7 @@ - (void)flushUIBlocksOnRootNode:(std::weak_ptr<RootNode>)rootNode {
#pragma mark - NativeRenderManager implementation
/**
* When NativeRenderUIManager received command to create view by node, NativeRenderUIManager must get all new created view ordered by index, set frames,
* When HippyUIManager received command to create view by node, it gets all new created view ordered by index, set frames,
* then insert them into superview one by one.
* Step:
* 1.create shadow views;
Expand Down Expand Up @@ -828,7 +818,7 @@ - (void)createRenderNodes:(std::vector<std::shared_ptr<DomNode>> &&)nodes
}];
}
}
[self addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self addUIBlock:^(HippyUIManager *uiManager, __unused NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
for (UIView *view in tempCreatedViews) {
[uiManager.viewRegistry addComponent:view forRootTag:rootNodeTag];
}
Expand All @@ -838,7 +828,7 @@ - (void)createRenderNodes:(std::vector<std::shared_ptr<DomNode>> &&)nodes
auto subViewIndices_ = subviewIndices;
HippyShadowView *renderObject = [self->_shadowViewRegistry componentForTag:@(tag) onRootTag:rootNodeTag];
if (HippyCreationTypeInstantly == [renderObject creationType] && !self->_uiCreationLazilyEnabled) {
[self addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
UIView *superView = viewRegistry[@(tag)];
for (NSUInteger index = 0; index < subViewTags_.size(); index++) {
UIView *subview = viewRegistry[@(subViewTags_[index])];
Expand All @@ -851,7 +841,7 @@ - (void)createRenderNodes:(std::vector<std::shared_ptr<DomNode>> &&)nodes
}];
}
}];
[self addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
HippyLogInfo(@"Created views: %lu, full registry: %lu", (unsigned long)tempCreatedViews.count, viewRegistry.count);
}];
}
Expand Down Expand Up @@ -915,7 +905,7 @@ - (void)deleteRenderNodesIds:(std::vector<std::shared_ptr<hippy::DomNode>> &&)no
}
__weak HippyUIManager *weakSelf = self;
auto strongNodes = std::move(nodes);
[self addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
HippyUIManager *strongSelf = weakSelf;
if (!strongSelf) {
return;
Expand Down Expand Up @@ -969,7 +959,7 @@ - (void)renderMoveViews:(const std::vector<int32_t> &&)ids
[fromObjectView didUpdateHippySubviews];
[toObjectView didUpdateHippySubviews];
auto strongTags = std::move(ids);
[self addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
UIView *fromView = [viewRegistry objectForKey:@(fromContainer)];
UIView *toView = [viewRegistry objectForKey:@(toContainer)];
for (int32_t tag : strongTags) {
Expand Down Expand Up @@ -1010,7 +1000,7 @@ - (void)renderMoveNodes:(std::vector<std::shared_ptr<hippy::DomNode>> &&)nodes
}
[parentObjectView didUpdateHippySubviews];
auto strongNodes = std::move(nodes);
[self addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
UIView *superView = nil;
for (auto node : strongNodes) {
int32_t index = node->GetIndex();
Expand Down Expand Up @@ -1048,7 +1038,7 @@ - (void)updateNodesLayout:(const std::vector<std::tuple<int32_t, hippy::LayoutRe
[renderObject dirtyPropagation:NativeRenderUpdateLifecycleLayoutDirtied];
renderObject.frame = frame;
renderObject.nodeLayoutResult = layoutResult;
[self addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
UIView *view = viewRegistry[componentTag];
/* do not use frame directly, because shadow view's frame possibly changed manually in
* [HippyShadowView collectRenderObjectHaveNewLayoutResults]
Expand Down Expand Up @@ -1404,7 +1394,7 @@ - (void)removeEventName:(const std::string &)eventName
}];
} else {
std::string name_ = eventName;
[self addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
UIView *view = [viewRegistry objectForKey:@(componentTag)];
[view removePropertyEvent:name_.c_str()];
}];
Expand Down Expand Up @@ -1483,8 +1473,7 @@ - (void)layoutAndMountOnRootNode:(std::weak_ptr<RootNode>)rootNode {
}];
}
[self addUIBlock:^(HippyUIManager *uiManager, __unused NSDictionary<NSNumber *, UIView *> *viewRegistry) {
NSSet<id<HippyComponent>> *nodes = [uiManager->_componentTransactionListeners copy];
for (id<HippyComponent> node in nodes) {
for (id<HippyComponent> node in uiManager->_componentTransactionListeners) {
[node hippyBridgeDidFinishTransaction];
}
}];
Expand Down
8 changes: 0 additions & 8 deletions renderer/native/ios/renderer/component/view/HippyShadowView.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ typedef void (^HippyViewInsertionBlock)(UIView *container, NSArray<UIView *> *ch
- (void)setLayoutFrame:(CGRect)frame;
- (void)setLayoutFrame:(CGRect)frame dirtyPropagation:(BOOL)dirtyPropagation;

/**
* Calculate property changes that need to be propagated to the view.
* The applierBlocks set contains NativeRenderApplierBlock functions that must be applied
* on the main thread in order to update the view.
*/
- (void)collectUpdatedProperties:(NSMutableSet<NativeRenderApplierBlock> *)applierBlocks
parentProperties:(NSDictionary<NSString *, id> *)parentProperties;

/**
* Process the updated properties and apply them to view. Shadow view classes
* that add additional propagating properties should override this method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ - (void)amendLayoutBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)blocks
return parentProperties;
}

- (void)collectUpdatedProperties:(NSMutableSet<NativeRenderApplierBlock> *)applierBlocks parentProperties:(NSDictionary<NSString *, id> *)parentProperties {
}

- (instancetype)init {
if ((self = [super init])) {
_propagationLifecycle = NativeRenderUpdateLifecycleUninitialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ - (HippyViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(__unused NSDict
}
}

HIPPY_EXPORT_METHOD(measureInWindow:(NSNumber *)componentTag
HIPPY_EXPORT_METHOD(measureInWindow:(nonnull NSNumber *)componentTag
callback:(HippyPromiseResolveBlock)callback) {
[self measureInWindow:componentTag withErrMsg:NO callback:callback];
}
Expand Down Expand Up @@ -114,7 +114,7 @@ - (void)measureInWindow:(NSNumber *)componentTag
}];
}

HIPPY_EXPORT_METHOD(measureInAppWindow:(NSNumber *)componentTag
HIPPY_EXPORT_METHOD(measureInAppWindow:(nonnull NSNumber *)componentTag
callback:(HippyPromiseResolveBlock)callback) {
[self measureInAppWindow:componentTag withErrMsg:NO callback:callback];
}
Expand Down
4 changes: 2 additions & 2 deletions renderer/native/ios/renderer/component/view/UIView+Hippy.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
* set true when hippy subviews changed, but subviews does not.
* set false after subviews does.
*/
@property (nonatomic, assign, getter=isNativeRenderSubviewsUpdated) BOOL nativeRenderSubviewsUpdated;
@property (nonatomic, assign, getter=isHippySubviewsUpdated) BOOL hippySubviewsUpdated;

/**
* The hippySubviews array, sorted by zIndex. This value is cached and
* automatically recalculated if views are added or removed.
*/
@property (nonatomic, copy, readonly) NSArray<UIView *> *sortedNativeRenderSubviews;
@property (nonatomic, copy, readonly) NSArray<UIView *> *sortedHippySubviews;

/**
* Updates the subviews array based on the hippySubviews. Default behavior is
Expand Down
12 changes: 6 additions & 6 deletions renderer/native/ios/renderer/component/view/UIView+Hippy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ - (void)setHippyZIndex:(NSInteger)zIndex {
objc_setAssociatedObject(self, @selector(hippyZIndex), @(zIndex), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (BOOL)isNativeRenderSubviewsUpdated {
- (BOOL)isHippySubviewsUpdated {
return [objc_getAssociatedObject(self, _cmd) integerValue];
}

- (void)setNativeRenderSubviewsUpdated:(BOOL)subViewsUpdated {
objc_setAssociatedObject(self, @selector(isNativeRenderSubviewsUpdated), @(subViewsUpdated), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- (void)setHippySubviewsUpdated:(BOOL)subViewsUpdated {
objc_setAssociatedObject(self, @selector(isHippySubviewsUpdated), @(subViewsUpdated), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (NSArray<UIView *> *)sortedNativeRenderSubviews {
- (NSArray<UIView *> *)sortedHippySubviews {
NSArray *subviews = objc_getAssociatedObject(self, _cmd);
if (!subviews) {
// Check if sorting is required - in most cases it won't be
Expand All @@ -269,11 +269,11 @@ - (void)setNativeRenderSubviewsUpdated:(BOOL)subViewsUpdated {
}

- (void)clearSortedSubviews {
objc_setAssociatedObject(self, @selector(sortedNativeRenderSubviews), nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(self, @selector(sortedHippySubviews), nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)didUpdateHippySubviews {
for (UIView *subview in self.sortedNativeRenderSubviews) {
for (UIView *subview in self.sortedHippySubviews) {
if (subview.superview != self) {
[subview sendAttachedToWindowEvent];
}
Expand Down
4 changes: 2 additions & 2 deletions renderer/native/ios/utils/HippyGradientObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ - (void)setLocationsCount:(NSUInteger)locationsCount {
}

- (void)setLocationValue:(NSNumber *)value atLocation:(NSUInteger)location {
NSAssert(location < _locationsCount, @"NativeRenderGradientLocationParser location out of range,try to insert value at %lu, but count is %lu", location, _locationsCount);
NSAssert(location < _locationsCount, @" location out of range, try to insert value at %lu, but count is %lu", location, _locationsCount);
[_locations replacePointerAtIndex:location withPointer:(__bridge void *)value];
}

Expand Down Expand Up @@ -356,5 +356,5 @@ void HippyDrawLinearGradientInContext(HippyGradientObject *object, CGContextRef

HIPPY_EXTERN void HippyDrawRadialGradientInContext(HippyGradientObject *object, CGContextRef context, CGSize size) {
NSCAssert(context, @"context cannot be null for drawing radial gradient");
NSCAssert(NO, @"NativeRenderDrawRadialGradientInContext not implemented");
NSCAssert(NO, @"HippyDrawRadialGradientInContext not implemented");
}

0 comments on commit c39dc12

Please sign in to comment.