Skip to content

Commit

Permalink
Missing moving pieces of RCTSurfaceHostingView
Browse files Browse the repository at this point in the history
Summary: Now it actually works.

Reviewed By: mmmulani

Differential Revision: D6701105

fbshipit-source-id: 16f3f4e319f874f9a08867b784d13aad4fa22aeb
  • Loading branch information
shergin authored and facebook-github-bot committed Jan 12, 2018
1 parent 7d9e902 commit 06ebaf2
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 18 deletions.
50 changes: 32 additions & 18 deletions React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ - (instancetype)initWithSurface:(RCTSurface *)surface
return self;
}

- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];

CGSize minimumSize;
CGSize maximumSize;

RCTSurfaceMinimumSizeAndMaximumSizeFromSizeAndSizeMeasureMode(
self.bounds.size,
_sizeMeasureMode,
minimumSize,
maximumSize
);

[_surface setMinimumSize:minimumSize
maximumSize:maximumSize];
}

- (CGSize)intrinsicContentSize
{
if (RCTSurfaceStageIsPreparing(_stage)) {
Expand All @@ -84,24 +102,15 @@ - (CGSize)sizeThatFits:(CGSize)size
return CGSizeZero;
}

CGSize minimumSize = CGSizeZero;
CGSize maximumSize = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);
CGSize minimumSize;
CGSize maximumSize;

if (_sizeMeasureMode & RCTSurfaceSizeMeasureModeWidthExact) {
minimumSize.width = size.width;
maximumSize.width = size.width;
}
else if (_sizeMeasureMode & RCTSurfaceSizeMeasureModeWidthAtMost) {
maximumSize.width = size.width;
}

if (_sizeMeasureMode & RCTSurfaceSizeMeasureModeHeightExact) {
minimumSize.height = size.height;
maximumSize.height = size.height;
}
else if (_sizeMeasureMode & RCTSurfaceSizeMeasureModeHeightAtMost) {
maximumSize.height = size.height;
}
RCTSurfaceMinimumSizeAndMaximumSizeFromSizeAndSizeMeasureMode(
size,
_sizeMeasureMode,
minimumSize,
maximumSize
);

return [_surface sizeThatFitsMinimumSize:minimumSize
maximumSize:maximumSize];
Expand Down Expand Up @@ -143,6 +152,8 @@ - (void)setIsActivityIndicatorViewVisible:(BOOL)visible
return;
}

_isActivityIndicatorViewVisible = visible;

if (visible) {
if (_activityIndicatorViewFactory) {
_activityIndicatorView = _activityIndicatorViewFactory();
Expand All @@ -164,6 +175,8 @@ - (void)setIsSurfaceViewVisible:(BOOL)visible
return;
}

_isSurfaceViewVisible = visible;

if (visible) {
_surfaceView = _surface.view;
_surfaceView.frame = self.bounds;
Expand All @@ -181,7 +194,7 @@ - (void)setActivityIndicatorViewFactory:(RCTSurfaceHostingViewActivityIndicatorV
{
_activityIndicatorViewFactory = activityIndicatorViewFactory;
if (_isActivityIndicatorViewVisible) {
_isActivityIndicatorViewVisible = NO;
self.isActivityIndicatorViewVisible = NO;
self.isActivityIndicatorViewVisible = YES;
}
}
Expand All @@ -190,6 +203,7 @@ - (void)setActivityIndicatorViewFactory:(RCTSurfaceHostingViewActivityIndicatorV

- (void)_invalidateLayout
{
[self invalidateIntrinsicContentSize];
[self.superview setNeedsLayout];
}

Expand Down
12 changes: 12 additions & 0 deletions React/Base/Surface/SurfaceHostingView/RCTSurfaceSizeMeasureMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import <UIKit/UIKit.h>

#import <React/RCTDefines.h>

/**
* Bitmask defines how size constrains from `-[UIView sizeThatFits:]`
* are translated to `-[RCTSurface sizeThatFitsMinimumSize:maximumSize:]`.
Expand All @@ -21,3 +23,13 @@ typedef NS_OPTIONS(NSInteger, RCTSurfaceSizeMeasureMode) {
RCTSurfaceSizeMeasureModeHeightExact = 1 << 2,
RCTSurfaceSizeMeasureModeHeightAtMost = 2 << 2,
};

/**
* Returns size constraints based on `size` and `sizeMeasureMode`.
*/
RCT_EXTERN void RCTSurfaceMinimumSizeAndMaximumSizeFromSizeAndSizeMeasureMode(
CGSize size,
RCTSurfaceSizeMeasureMode sizeMeasureMode,
CGSize &minimumSize,
CGSize &maximumSize
);
38 changes: 38 additions & 0 deletions React/Base/Surface/SurfaceHostingView/RCTSurfaceSizeMeasureMode.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import <UIKit/UIKit.h>

#import "RCTSurfaceSizeMeasureMode.h"

void RCTSurfaceMinimumSizeAndMaximumSizeFromSizeAndSizeMeasureMode(
CGSize size,
RCTSurfaceSizeMeasureMode sizeMeasureMode,
CGSize &minimumSize,
CGSize &maximumSize
) {
minimumSize = CGSizeZero;
maximumSize = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);

if (sizeMeasureMode & RCTSurfaceSizeMeasureModeWidthExact) {
minimumSize.width = size.width;
maximumSize.width = size.width;
}
else if (sizeMeasureMode & RCTSurfaceSizeMeasureModeWidthAtMost) {
maximumSize.width = size.width;
}

if (sizeMeasureMode & RCTSurfaceSizeMeasureModeHeightExact) {
minimumSize.height = size.height;
maximumSize.height = size.height;
}
else if (sizeMeasureMode & RCTSurfaceSizeMeasureModeHeightAtMost) {
maximumSize.height = size.height;
}
}
6 changes: 6 additions & 0 deletions React/React.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@
590D7BFE1EBD458B00D8A370 /* RCTShadowView+Layout.h in Headers */ = {isa = PBXBuildFile; fileRef = 590D7BFB1EBD458B00D8A370 /* RCTShadowView+Layout.h */; };
590D7BFF1EBD458B00D8A370 /* RCTShadowView+Layout.m in Sources */ = {isa = PBXBuildFile; fileRef = 590D7BFC1EBD458B00D8A370 /* RCTShadowView+Layout.m */; };
590D7C001EBD458B00D8A370 /* RCTShadowView+Layout.m in Sources */ = {isa = PBXBuildFile; fileRef = 590D7BFC1EBD458B00D8A370 /* RCTShadowView+Layout.m */; };
5925356A20084D0600DD584B /* RCTSurfaceSizeMeasureMode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5925356920084D0600DD584B /* RCTSurfaceSizeMeasureMode.mm */; };
5925356B20084D0600DD584B /* RCTSurfaceSizeMeasureMode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5925356920084D0600DD584B /* RCTSurfaceSizeMeasureMode.mm */; };
59283CA01FD67321000EAAB9 /* RCTSurfaceStage.m in Sources */ = {isa = PBXBuildFile; fileRef = 59283C9F1FD67320000EAAB9 /* RCTSurfaceStage.m */; };
59283CA11FD67321000EAAB9 /* RCTSurfaceStage.m in Sources */ = {isa = PBXBuildFile; fileRef = 59283C9F1FD67320000EAAB9 /* RCTSurfaceStage.m */; };
594F0A321FD23228007FBE96 /* RCTSurfaceHostingView.h in Headers */ = {isa = PBXBuildFile; fileRef = 594F0A2F1FD23228007FBE96 /* RCTSurfaceHostingView.h */; };
Expand Down Expand Up @@ -2157,6 +2159,7 @@
58C571C01AA56C1900CDF9C8 /* RCTDatePickerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RCTDatePickerManager.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
590D7BFB1EBD458B00D8A370 /* RCTShadowView+Layout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTShadowView+Layout.h"; sourceTree = "<group>"; };
590D7BFC1EBD458B00D8A370 /* RCTShadowView+Layout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTShadowView+Layout.m"; sourceTree = "<group>"; };
5925356920084D0600DD584B /* RCTSurfaceSizeMeasureMode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTSurfaceSizeMeasureMode.mm; sourceTree = "<group>"; };
59283C9F1FD67320000EAAB9 /* RCTSurfaceStage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTSurfaceStage.m; sourceTree = "<group>"; };
594F0A2F1FD23228007FBE96 /* RCTSurfaceHostingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTSurfaceHostingView.h; sourceTree = "<group>"; };
594F0A301FD23228007FBE96 /* RCTSurfaceHostingView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTSurfaceHostingView.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2765,6 +2768,7 @@
594F0A2F1FD23228007FBE96 /* RCTSurfaceHostingView.h */,
594F0A301FD23228007FBE96 /* RCTSurfaceHostingView.mm */,
594F0A311FD23228007FBE96 /* RCTSurfaceSizeMeasureMode.h */,
5925356920084D0600DD584B /* RCTSurfaceSizeMeasureMode.mm */,
);
path = SurfaceHostingView;
sourceTree = "<group>";
Expand Down Expand Up @@ -4164,6 +4168,7 @@
3D7BFD181EA8E351008DFB7A /* RCTPackagerClient.m in Sources */,
2D3B5EA71D9B08CE00451313 /* RCTTouchHandler.m in Sources */,
59D031F01F8353D3008361F0 /* RCTSafeAreaShadowView.m in Sources */,
5925356B20084D0600DD584B /* RCTSurfaceSizeMeasureMode.mm in Sources */,
3D05745A1DE5FFF500184BB4 /* RCTJavaScriptLoader.mm in Sources */,
2D3B5EA41D9B08C200451313 /* RCTPerformanceLogger.m in Sources */,
3DCE53251FEAB1E000613583 /* RCTShadowView.m in Sources */,
Expand Down Expand Up @@ -4477,6 +4482,7 @@
58114A161AAE854800E7D092 /* RCTPicker.m in Sources */,
137327E81AA5CF210034F82E /* RCTTabBarItem.m in Sources */,
83A1FE8C1B62640A00BE0E65 /* RCTModalHostView.m in Sources */,
5925356A20084D0600DD584B /* RCTSurfaceSizeMeasureMode.mm in Sources */,
9936F3371F5F2F480010BF04 /* PrivateDataBase.cpp in Sources */,
1450FF871BCFF28A00208362 /* RCTProfileTrampoline-arm.S in Sources */,
131B6AF51AF1093D00FFC3E0 /* RCTSegmentedControlManager.m in Sources */,
Expand Down

0 comments on commit 06ebaf2

Please sign in to comment.