Browse Source

Fix react view title fill alignment (#5681)

React view title layout didn't recalculated it size on orientation change which caused it to look bad on iPads.
Yogev Ben David 5 years ago
parent
commit
619af3efe0
1 changed files with 13 additions and 2 deletions
  1. 13
    2
      lib/ios/RNNReactView.m

+ 13
- 2
lib/ios/RNNReactView.m View File

2
 #import "RCTHelpers.h"
2
 #import "RCTHelpers.h"
3
 #import <React/RCTUIManager.h>
3
 #import <React/RCTUIManager.h>
4
 
4
 
5
-@implementation RNNReactView
5
+@implementation RNNReactView {
6
+	BOOL _fillParent;
7
+}
6
 
8
 
7
 - (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties availableSize:(CGSize)availableSize reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
9
 - (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties availableSize:(CGSize)availableSize reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
8
 	self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
10
 	self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
44
 	}
46
 	}
45
 }
47
 }
46
 
48
 
49
+- (CGSize)intrinsicContentSize {
50
+	if (_fillParent) {
51
+		return UILayoutFittingExpandedSize;
52
+	} else {
53
+		return [super intrinsicContentSize];
54
+	}
55
+}
56
+
47
 - (void)setAlignment:(NSString *)alignment inFrame:(CGRect)frame {
57
 - (void)setAlignment:(NSString *)alignment inFrame:(CGRect)frame {
48
 	if ([alignment isEqualToString:@"fill"]) {
58
 	if ([alignment isEqualToString:@"fill"]) {
59
+		_fillParent = YES;
60
+		self.translatesAutoresizingMaskIntoConstraints = NO;
49
 		self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
61
 		self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
50
-		[self setFrame:frame];
51
 	} else {
62
 	} else {
52
 		self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
63
 		self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
53
 		__weak RNNReactView *weakSelf = self;
64
 		__weak RNNReactView *weakSelf = self;