Skip to content

Commit 887b53d

Browse files
committed
fix(ios): dynamic size adaptation support of modal component (#4285)
1 parent 7612c13 commit 887b53d

File tree

4 files changed

+15
-41
lines changed

4 files changed

+15
-41
lines changed

renderer/native/ios/renderer/HippyUIManager.mm

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -425,27 +425,28 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
425425
}
426426
}
427427

428-
- (void)setFrame:(CGRect)frame forView:(UIView *)view{
428+
- (void)setFrame:(CGRect)frame forView:(UIView *)view {
429429
NSNumber* hippyTag = view.hippyTag;
430430
NSNumber* rootTag = view.rootTag;
431431

432432
auto domManager = _domManager.lock();
433433
if (!domManager) {
434434
return;
435435
}
436-
__weak id weakSelf = self;
436+
437+
__weak __typeof(self)weakSelf = self;
437438
std::vector<std::function<void()>> ops_ = {[hippyTag, rootTag, weakSelf, frame]() {
438-
HippyUIManager *strongSelf = weakSelf;
439+
__strong __typeof(weakSelf)strongSelf = weakSelf;
439440
if (!strongSelf) {
440441
return;
441442
}
442-
HippyShadowView *renderObject = [strongSelf->_shadowViewRegistry componentForTag:hippyTag onRootTag:rootTag];
443-
if (renderObject == nil) {
443+
HippyShadowView *shadowView = [strongSelf->_shadowViewRegistry componentForTag:hippyTag onRootTag:rootTag];
444+
if (!shadowView) {
444445
return;
445446
}
446447

447-
if (!HippyCGRectRoundInPixelNearlyEqual(frame, renderObject.frame)) {
448-
[renderObject setLayoutFrame:frame];
448+
if (!HippyCGRectRoundInPixelNearlyEqual(frame, shadowView.frame)) {
449+
[shadowView setLayoutFrame:frame];
449450
std::weak_ptr<RootNode> rootNode = [strongSelf->_shadowViewRegistry rootNodeForTag:rootTag];
450451
[strongSelf batchOnRootNode:rootNode];
451452
}
@@ -1073,19 +1074,19 @@ - (void)updateNodesLayout:(const std::vector<std::tuple<int32_t, hippy::LayoutRe
10731074
NSNumber *componentTag = @(tag);
10741075
hippy::LayoutResult layoutResult = std::get<1>(layoutInfoTuple);
10751076
CGRect frame = CGRectMakeFromLayoutResult(layoutResult);
1076-
HippyShadowView *renderObject = [_shadowViewRegistry componentForTag:componentTag onRootTag:rootTag];
1077-
if (renderObject) {
1078-
[renderObject dirtyPropagation:NativeRenderUpdateLifecycleLayoutDirtied];
1079-
renderObject.frame = frame;
1080-
renderObject.nodeLayoutResult = layoutResult;
1077+
HippyShadowView *shadowView = [_shadowViewRegistry componentForTag:componentTag onRootTag:rootTag];
1078+
if (shadowView) {
1079+
[shadowView dirtyPropagation:NativeRenderUpdateLifecycleLayoutDirtied];
1080+
shadowView.frame = frame;
1081+
shadowView.nodeLayoutResult = layoutResult;
10811082
[self addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
10821083
UIView *view = viewRegistry[componentTag];
10831084
/* do not use frame directly, because shadow view's frame possibly changed manually in
10841085
* [HippyShadowView collectRenderObjectHaveNewLayoutResults]
10851086
* This is a Wrong example:
10861087
* [view hippySetFrame:frame]
10871088
*/
1088-
[view hippySetFrame:renderObject.frame];
1089+
[view hippySetFrame:shadowView.frame];
10891090
}];
10901091
}
10911092
}

renderer/native/ios/renderer/component/modal/HippyModalHostView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ - (instancetype)initWithBridge:(HippyBridge *)bridge {
6262

6363
- (void)notifyForBoundsChange:(CGRect)newBounds {
6464
if (_isPresented) {
65+
[[_bridge uiManager] setFrame:newBounds forView:self];
6566
[[_bridge uiManager] setFrame:newBounds forView:_hippySubview];
6667
[self notifyForOrientationChange];
6768
}
@@ -89,7 +90,6 @@ - (void)insertHippySubview:(UIView *)subview atIndex:(NSInteger)atIndex {
8990
HippyAssert(_hippySubview == nil, @"Modal view can only have one subview");
9091
[super insertHippySubview:subview atIndex:atIndex];
9192
[subview addGestureRecognizer:_touchHandler];
92-
subview.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
9393

9494
[_modalViewController.view insertSubview:subview atIndex:0];
9595
[subview sendAttachedToWindowEvent];

renderer/native/ios/renderer/component/modal/HippyModalHostViewController.mm renamed to renderer/native/ios/renderer/component/modal/HippyModalHostViewController.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ - (BOOL)prefersStatusBarHidden {
8080
return hidden;
8181
}
8282

83-
#if HIPPY_DEBUG
8483
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
8584
UIWindow *keyWindow = HippyKeyWindow();
8685
UIInterfaceOrientationMask appSupportedOrientationsMask = [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:keyWindow];
@@ -90,6 +89,5 @@ - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
9089

9190
return _supportedInterfaceOrientations;
9291
}
93-
#endif // HIPPY_DEBUG
9492

9593
@end

renderer/native/ios/renderer/component/modal/HippyModalHostViewManager.mm

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,11 @@
2626
#import "HippyModalTransitioningDelegate.h"
2727
#import "HippyShadowView.h"
2828
#import "HippyShadowView+Internal.h"
29-
#import "HippyRenderUtils.h"
3029

3130

3231
NSString * const HippyModalHostViewDismissNotification = @"HippyModalHostViewDismissNotification";
3332

3433

35-
@interface HippyModalHostShadowView : HippyShadowView
36-
37-
@end
38-
39-
@implementation HippyModalHostShadowView
40-
41-
- (void)insertHippySubview:(HippyShadowView *)subview atIndex:(NSUInteger)atIndex{
42-
[super insertHippySubview:subview atIndex:atIndex];
43-
CGRect frame = { .origin = CGPointZero, .size = HippyScreenSize() };
44-
[subview setLayoutFrame:frame];
45-
}
46-
47-
- (void)setDomManager:(std::weak_ptr<hippy::DomManager>)domManager {
48-
[super setDomManager:domManager];
49-
CGRect frame = { .origin = CGPointZero, .size = HippyScreenSize() };
50-
[self setLayoutFrame:frame];
51-
}
52-
53-
@end
54-
5534
@implementation HippyModalHostViewManager
5635

5736
HIPPY_EXPORT_MODULE(Modal)
@@ -83,10 +62,6 @@ - (UIView *)view {
8362
return _transitioningDelegate;
8463
}
8564

86-
- (HippyShadowView *)shadowView {
87-
return [HippyModalHostShadowView new];
88-
}
89-
9065
- (void)invalidate {
9166
for (HippyModalHostView *hostView in _hostViews) {
9267
[hostView invalidate];

0 commit comments

Comments
 (0)