Files
react-native/Examples/UIExplorer/UIExplorer/NativeExampleViews/FlexibleSizeExampleView.m
Pieter De Baets e1577df1fd Move all header imports to "<React/..>"
Summary:
To make React Native play nicely with our internal build infrastructure we need to properly namespace all of our header includes.

Where previously you could do `#import "RCTBridge.h"`, you must now write this as `#import <React/RCTBridge.h>`. If your xcode project still has a custom header include path, both variants will likely continue to work, but for new projects, we're defaulting the header include path to `$(BUILT_PRODUCTS_DIR)/usr/local/include`, where the React and CSSLayout targets will copy a subset of headers too. To make Xcode copy headers phase work properly, you may need to add React as an explicit dependency to your app's scheme and disable "parallelize build".

Reviewed By: mmmulani

Differential Revision: D4213120

fbshipit-source-id: 84a32a4b250c27699e6795f43584f13d594a9a82
2016-11-23 07:58:39 -08:00

121 lines
3.5 KiB
Objective-C

/**
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#import "FlexibleSizeExampleView.h"
#import <React/RCTBridge.h>
#import <React/RCTRootView.h>
#import <React/RCTRootViewDelegate.h>
#import <React/RCTViewManager.h>
#import "AppDelegate.h"
@interface FlexibleSizeExampleViewManager : RCTViewManager
@end
@implementation FlexibleSizeExampleViewManager
RCT_EXPORT_MODULE();
- (UIView *)view
{
return [FlexibleSizeExampleView new];
}
@end
@interface FlexibleSizeExampleView () <RCTRootViewDelegate>
@end
@implementation FlexibleSizeExampleView
{
RCTRootView *_resizableRootView;
UITextView *_currentSizeTextView;
BOOL _sizeUpdated;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
_sizeUpdated = NO;
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
_resizableRootView = [[RCTRootView alloc] initWithBridge:appDelegate.bridge
moduleName:@"RootViewSizeFlexibilityExampleApp"
initialProperties:@{}];
[_resizableRootView setSizeFlexibility:RCTRootViewSizeFlexibilityHeight];
_currentSizeTextView = [UITextView new];
#ifndef TARGET_OS_TV
_currentSizeTextView.editable = NO;
#endif
_currentSizeTextView.text = @"Resizable view has not been resized yet";
_currentSizeTextView.textColor = [UIColor blackColor];
_currentSizeTextView.backgroundColor = [UIColor whiteColor];
_currentSizeTextView.font = [UIFont boldSystemFontOfSize:10];
_resizableRootView.delegate = self;
[self addSubview:_currentSizeTextView];
[self addSubview:_resizableRootView];
}
return self;
}
- (void)layoutSubviews
{
float textViewHeight = 60;
float spacingHeight = 10;
[_resizableRootView setFrame:CGRectMake(0, textViewHeight + spacingHeight, self.frame.size.width, _resizableRootView.frame.size.height)];
[_currentSizeTextView setFrame:CGRectMake(0, 0, self.frame.size.width, textViewHeight)];
}
- (NSArray<UIView<RCTComponent> *> *)reactSubviews
{
// this is to avoid unregistering our RCTRootView when the component is removed from RN hierarchy
(void)[super reactSubviews];
return @[];
}
#pragma mark - RCTRootViewDelegate
- (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView
{
CGRect newFrame = rootView.frame;
newFrame.size = rootView.intrinsicSize;
if (!_sizeUpdated) {
_sizeUpdated = TRUE;
_currentSizeTextView.text = [NSString stringWithFormat:@"RCTRootViewDelegate: content with initially unknown size has appeared, updating root view's size so the content fits."];
} else {
_currentSizeTextView.text = [NSString stringWithFormat:@"RCTRootViewDelegate: content size has been changed to (%ld, %ld), updating root view's size.",
(long)newFrame.size.width,
(long)newFrame.size.height];
}
rootView.frame = newFrame;
}
@end