Skip to content

Commit

Permalink
fix(ios): fix modal view display issue in landscape mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ruifanyuan authored and hippy-actions[bot] committed Nov 29, 2023
1 parent c379fc3 commit 2edbab2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
9 changes: 8 additions & 1 deletion renderer/native/ios/renderer/HippyUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,20 @@
/// - rootTag: NSNumber
- (HippyShadowView *)shadowViewForHippyTag:(NSNumber *)hippyTag onRootTag:(NSNumber *)rootTag;

/// Update the frame of a view. This might be in response to a screen rotation
/// Update the frame of a root view. This might be in response to a screen rotation
/// or some other layout event outside of the Hippy-managed view hierarchy.
/// - Parameters:
/// - frame: new frame
/// - view: target view
- (void)setFrame:(CGRect)frame forRootView:(UIView *)view;

/// Update the frame of a view. This might be in response to a screen rotation
/// or some other layout event outside of the Hippy-managed view hierarchy.
/// - Parameters:
/// - frame: new frame
/// - view: target view
- (void)setFrame:(CGRect)frame forView:(UIView *)view;

/// Schedule a block to be executed on the UI thread. Useful if you need to execute
/// view logic after all currently queued view updates have completed.
/// - Parameter block: block to be executed on main thread
Expand Down
29 changes: 29 additions & 0 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,35 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
}
}
- (void)setFrame:(CGRect)frame forView:(UIView *)view{
NSNumber* hippyTag = view.hippyTag;
NSNumber* rootTag = view.rootTag;
auto domManager = _domManager.lock();
if (!domManager) {
return;
}
__weak id weakSelf = self;
std::vector<std::function<void()>> ops_ = {[hippyTag, rootTag, weakSelf, frame]() {
if (!weakSelf) {
return;
}
HippyUIManager *strongSelf = weakSelf;
HippyShadowView *renderObject = [strongSelf->_shadowViewRegistry componentForTag:hippyTag onRootTag:rootTag];
if (renderObject == nil) {
return;
}
if (!CGRectEqualToRect(frame, renderObject.frame)) {
//renderObject.frame = frame;
[renderObject setLayoutFrame:frame];
std::weak_ptr<RootNode> rootNode = [strongSelf->_shadowViewRegistry rootNodeForTag:rootTag];
[strongSelf batchOnRootNode:rootNode];
}
}};
domManager->PostTask(hippy::dom::Scene(std::move(ops_)));
}
- (void)setFrame:(CGRect)frame forRootView:(UIView *)view {
AssertMainQueue();
NSNumber *componentTag = view.hippyTag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@
#import "HippyModalHostViewInteractor.h"
#import "HippyAssert.h"
#import "UIView+MountEvent.h"

#import "HippyUIManager.h"

@implementation HippyModalHostView {
BOOL _isPresented;
HippyModalHostViewController *_modalViewController;
UIView *_hippySubview;
UIStatusBarStyle originStyle;
UIInterfaceOrientation _lastKnownOrientation;
HippyBridge *_bridge;
}

HIPPY_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame)
HIPPY_NOT_IMPLEMENTED(-(instancetype)initWithCoder : coder)

- (instancetype)initWithBridge:(HippyBridge *)bridge {
if ((self = [super initWithFrame:CGRectZero])) {
_bridge = bridge;
_modalViewController = [HippyModalHostViewController new];
UIView *containerView = [UIView new];
containerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
Expand All @@ -60,6 +62,7 @@ - (instancetype)initWithBridge:(HippyBridge *)bridge {

- (void)notifyForBoundsChange:(CGRect)newBounds {
if (_isPresented) {
[[_bridge uiManager] setFrame:newBounds forView:_hippySubview];
[self notifyForOrientationChange];
}
}
Expand Down

0 comments on commit 2edbab2

Please sign in to comment.