Skip to content

Commit

Permalink
Fix truncated bottom tab title on iPads (#7710)
Browse files Browse the repository at this point in the history
Closes #7506, closes #6923
  • Loading branch information
yogevbd committed May 14, 2023
1 parent 438e10a commit dcff945
Show file tree
Hide file tree
Showing 29 changed files with 131 additions and 130 deletions.
2 changes: 1 addition & 1 deletion lib/ios/BottomTabsTogetherAttacher.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ @implementation BottomTabsTogetherAttacher
- (void)attach:(RNNBottomTabsController *)bottomTabsController {
dispatch_group_t ready = dispatch_group_create();

for (UIViewController *vc in bottomTabsController.pendingChildViewControllers) {
for (UIViewController *vc in bottomTabsController.childViewControllers) {
dispatch_group_enter(ready);
[vc setReactViewReadyCallback:^{
dispatch_group_leave(ready);
Expand Down
25 changes: 13 additions & 12 deletions lib/ios/RCTConvert+Interpolation.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ @implementation RCTConvert (Interpolation)
}
NSString *interpolation = json[@"type"] ? json[@"type"] : nil;

id<Interpolator> (^interpolator)(void) = @{
@"decelerate" : ^{
CGFloat factor = [[[NumberParser parse:json key:@"factor"]
withDefault:[NSNumber numberWithFloat:1.0f]] floatValue];
return [[DecelerateInterpolator alloc] init:factor];
},
id<Interpolator> (^interpolator)(void) = @{@"decelerate" : ^{
CGFloat factor = [[[NumberParser parse:json key:@"factor"]
withDefault:[NSNumber numberWithFloat:1.0f]] floatValue];
return [[DecelerateInterpolator alloc] init:factor];
}
,
@"accelerate" : ^{
CGFloat factor = [[[NumberParser parse:json key:@"factor"]
withDefault:[NSNumber numberWithFloat:1.0f]] floatValue];
Expand Down Expand Up @@ -72,13 +72,14 @@ @implementation RCTConvert (Interpolation)
allowsOverdamping:allowsOverdamping
initialVelocity:initialVelocity];
},
}[interpolation];
}
[interpolation];

if (interpolator != nil) {
return interpolator();
} else {
return [RCTConvert defaultInterpolator];
}
if (interpolator != nil) {
return interpolator();
} else {
return [RCTConvert defaultInterpolator];
}
}

@end
4 changes: 2 additions & 2 deletions lib/ios/RNNBaseIconCreator.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#import <Foundation/Foundation.h>
#import "RNNButtonOptions.h"
#import "RNNIconDrawer.h"
#import "UIImage+utils.h"
#import <Foundation/Foundation.h>

@interface RNNBaseIconCreator : NSObject

- (instancetype)initWithIconDrawer:(RNNIconDrawer *)iconDrawer;

- (UIImage *)create:(RNNButtonOptions *)buttonOptions;

@property (nonatomic, retain) RNNIconDrawer* iconDrawer;
@property(nonatomic, retain) RNNIconDrawer *iconDrawer;

@end

Expand Down
62 changes: 31 additions & 31 deletions lib/ios/RNNBaseIconCreator.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,62 @@
@implementation RNNBaseIconCreator

- (instancetype)initWithIconDrawer:(RNNIconDrawer *)iconDrawer {
self = [super init];
self.iconDrawer = iconDrawer;
return self;
self = [super init];
self.iconDrawer = iconDrawer;
return self;
}

- (UIImage *)create:(RNNButtonOptions *)buttonOptions {
if (buttonOptions.isEnabled)
return [self createEnabledIcon:buttonOptions];
else
return [self createDisabledIcon:buttonOptions];
if (buttonOptions.isEnabled)
return [self createEnabledIcon:buttonOptions];
else
return [self createDisabledIcon:buttonOptions];
}

- (UIImage *)createEnabledIcon:(RNNButtonOptions *)buttonOptions {
UIColor *backgroundColor = [buttonOptions.iconBackground.color withDefault:UIColor.clearColor];
UIColor *tintColor = [buttonOptions.color withDefault:nil];
UIColor *backgroundColor = [buttonOptions.iconBackground.color withDefault:UIColor.clearColor];
UIColor *tintColor = [buttonOptions.color withDefault:nil];

return [self createIcon:buttonOptions tintColor:tintColor backgroundColor:backgroundColor];
return [self createIcon:buttonOptions tintColor:tintColor backgroundColor:backgroundColor];
}

- (UIImage *)createDisabledIcon:(RNNButtonOptions *)buttonOptions {
UIColor *backgroundColor = [self resolveDisabledBackgroundColor:buttonOptions];
UIColor *tintColor = [self resolveDisabledIconColor:buttonOptions];
UIColor *backgroundColor = [self resolveDisabledBackgroundColor:buttonOptions];
UIColor *tintColor = [self resolveDisabledIconColor:buttonOptions];

return [self createIcon:buttonOptions tintColor:tintColor backgroundColor:backgroundColor];
return [self createIcon:buttonOptions tintColor:tintColor backgroundColor:backgroundColor];
}

- (UIColor *)resolveDisabledIconColor:(RNNButtonOptions *)buttonOptions {
if (![buttonOptions.enabled withDefault:YES] && buttonOptions.disabledColor.hasValue)
return buttonOptions.disabledColor.get;
else
return [buttonOptions.color withDefault:nil];
if (![buttonOptions.enabled withDefault:YES] && buttonOptions.disabledColor.hasValue)
return buttonOptions.disabledColor.get;
else
return [buttonOptions.color withDefault:nil];
}

- (UIColor *)resolveDisabledBackgroundColor:(RNNButtonOptions *)buttonOptions {
if (![buttonOptions.enabled withDefault:YES] &&
buttonOptions.iconBackground.disabledColor.hasValue)
return buttonOptions.iconBackground.disabledColor.get;
else
return [buttonOptions.iconBackground.color withDefault:nil];
if (![buttonOptions.enabled withDefault:YES] &&
buttonOptions.iconBackground.disabledColor.hasValue)
return buttonOptions.iconBackground.disabledColor.get;
else
return [buttonOptions.iconBackground.color withDefault:nil];
}

- (UIImage *)createIcon:(RNNButtonOptions *)buttonOptions
tintColor:(UIColor *)tintColor
backgroundColor:(UIColor *)backgroundColor {
tintColor:(UIColor *)tintColor
backgroundColor:(UIColor *)backgroundColor {
@throw @"createIcon should be implemented by subclass";
return nil;
}

- (CGSize)resolveIconSize:(RNNButtonOptions *)buttonOptions {
CGFloat width =
[buttonOptions.iconBackground.width withDefault:@(buttonOptions.icon.get.size.width)]
.floatValue;
CGFloat height =
[buttonOptions.iconBackground.height withDefault:@(buttonOptions.icon.get.size.height)]
.floatValue;
return CGSizeMake(width, height);
CGFloat width =
[buttonOptions.iconBackground.width withDefault:@(buttonOptions.icon.get.size.width)]
.floatValue;
CGFloat height =
[buttonOptions.iconBackground.height withDefault:@(buttonOptions.icon.get.size.height)]
.floatValue;
return CGSizeMake(width, height);
}

@end
2 changes: 0 additions & 2 deletions lib/ios/RNNBottomTabsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@

- (void)handleTabBarLongPress:(CGPoint)locationInTabBar;

@property(nonatomic, strong) NSArray *pendingChildViewControllers;

@end
35 changes: 16 additions & 19 deletions lib/ios/RNNBottomTabsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
@interface RNNBottomTabsController ()
@property(nonatomic, strong) BottomTabPresenter *bottomTabPresenter;
@property(nonatomic, strong) RNNDotIndicatorPresenter *dotIndicatorPresenter;
@property(nonatomic) BOOL viewWillAppearOnce;
@property(nonatomic, strong) UILongPressGestureRecognizer *longPressRecognizer;

@end
Expand All @@ -29,7 +28,7 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
_bottomTabsAttacher = bottomTabsAttacher;
_bottomTabPresenter = bottomTabPresenter;
_dotIndicatorPresenter = dotIndicatorPresenter;
_pendingChildViewControllers = childViewControllers;

self = [super initWithLayoutInfo:layoutInfo
creator:creator
options:options
Expand All @@ -56,18 +55,27 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
return self;
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// This hack is needed for cases when the initialized state of the tabBar should be hidden
UINavigationController *firstChild = [self.childViewControllers objectAtIndex:0];
if ([firstChild isKindOfClass:UINavigationController.class] &&
firstChild.hidesBottomBarWhenPushed) {
[firstChild pushViewController:UIViewController.new animated:NO];
[firstChild popViewControllerAnimated:NO];
}
}

- (void)viewDidLoad {
[super viewDidLoad];
}

- (void)createTabBarItems:(NSArray<UIViewController *> *)childViewControllers {
for (UIViewController *child in childViewControllers) {
[_bottomTabPresenter applyOptions:child.resolveOptions child:child];
}
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_viewWillAppearOnce = YES;
[self loadChildren:self.pendingChildViewControllers];
}

- (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewController *)child {
[super mergeChildOptions:options child:child];
UIViewController *childViewController = [self findViewController:child];
Expand Down Expand Up @@ -124,23 +132,12 @@ - (UIViewController *)selectedViewController {
return self.childViewControllers.count ? self.childViewControllers[_currentTabIndex] : nil;
}

- (NSArray<__kindof UIViewController *> *)childViewControllers {
return self.pendingChildViewControllers ?: super.childViewControllers;
}

- (void)setSelectedViewController:(__kindof UIViewController *)selectedViewController {
_previousTabIndex = _currentTabIndex;
_currentTabIndex = [self.childViewControllers indexOfObject:selectedViewController];
[super setSelectedViewController:selectedViewController];
}

- (void)loadChildren:(NSArray *)children {
if (self.viewWillAppearOnce) {
[super loadChildren:children];
self.pendingChildViewControllers = nil;
}
}

- (void)setTabBarVisible:(BOOL)visible animated:(BOOL)animated {
_tabBarNeedsRestore = YES;
visible ? [self showTabBar:animated] : [self hideTabBar:animated];
Expand Down
4 changes: 2 additions & 2 deletions lib/ios/RNNButtonBuilder.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNNButtonBuilder.h"
#import "RNNFontAttributesCreator.h"
#import "RNNDynamicIconCreator.h"
#import "RNNFontAttributesCreator.h"

@implementation RNNButtonBuilder {
RNNReactComponentRegistry *_componentRegistry;
Expand All @@ -15,7 +15,7 @@ - (instancetype)initWithComponentRegistry:(id)componentRegistry {
} else {
_iconCreator = [[RNNIconCreator alloc] initWithIconDrawer:RNNIconDrawer.new];
}

return self;
}

Expand Down
10 changes: 6 additions & 4 deletions lib/ios/RNNComponentPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,15 @@ - (void)mergeOptions:(RNNNavigationOptions *)mergeOptions
if (mergeOptions.topBar.rightButtonColor.hasValue) {
[_buttonsPresenter applyRightButtonsColor:mergeOptions.topBar.rightButtonColor];
}

if (mergeOptions.topBar.rightButtonBackgroundColor.hasValue) {
[_buttonsPresenter applyRightButtonsBackgroundColor:mergeOptions.topBar.rightButtonBackgroundColor];
[_buttonsPresenter
applyRightButtonsBackgroundColor:mergeOptions.topBar.rightButtonBackgroundColor];
}

if (mergeOptions.topBar.leftButtonBackgroundColor.hasValue) {
[_buttonsPresenter applyLeftButtonsBackgroundColor:mergeOptions.topBar.leftButtonBackgroundColor];
[_buttonsPresenter
applyLeftButtonsBackgroundColor:mergeOptions.topBar.leftButtonBackgroundColor];
}

if (mergeOptions.overlay.interceptTouchOutside.hasValue) {
Expand Down
1 change: 0 additions & 1 deletion lib/ios/RNNComponentRootView.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
initialProperties:initialProperties
eventEmitter:eventEmitter
reactViewReadyBlock:reactViewReadyBlock];
[bridge.uiManager setAvailableSize:UIScreen.mainScreen.bounds.size forRootView:self];
return self;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNDynamicIconCreator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import <Foundation/Foundation.h>
#import "RNNBaseIconCreator.h"
#import <Foundation/Foundation.h>

@interface RNNDynamicIconCreator : RNNBaseIconCreator

Expand Down
45 changes: 29 additions & 16 deletions lib/ios/RNNDynamicIconCreator.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,35 @@ - (UIImage *)createIcon:(RNNButtonOptions *)buttonOptions
UIImage *iconImage = buttonOptions.icon.get;
CGSize iconSize = [self resolveIconSize:buttonOptions];
CGFloat cornerRadius = [buttonOptions.iconBackground.cornerRadius withDefault:@(0)].floatValue;
UIColor *lightColor = [tintColor resolvedColorWithTraitCollection:[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]];
UIColor *darkColor = [tintColor resolvedColorWithTraitCollection:[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]];
UIColor *lightBackgroundColor = [backgroundColor resolvedColorWithTraitCollection:[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]];
UIColor *darkBackgroundColor = [backgroundColor resolvedColorWithTraitCollection:[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]];
UIImage *darkImage = [[self.iconDrawer draw:iconImage
imageColor:darkColor
backgroundColor:darkBackgroundColor
size:iconSize
cornerRadius:cornerRadius] imageWithInsets:buttonOptions.iconInsets.UIEdgeInsets];
UIImage *lightImage = [[self.iconDrawer draw:iconImage
imageColor:lightColor
backgroundColor:lightBackgroundColor
size:iconSize
cornerRadius:cornerRadius] imageWithInsets:buttonOptions.iconInsets.UIEdgeInsets];
[lightImage.imageAsset registerImage:darkImage withTraitCollection:[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]];

UIColor *lightColor = [tintColor
resolvedColorWithTraitCollection:
[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]];
UIColor *darkColor = [tintColor
resolvedColorWithTraitCollection:
[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]];
UIColor *lightBackgroundColor = [backgroundColor
resolvedColorWithTraitCollection:
[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]];
UIColor *darkBackgroundColor = [backgroundColor
resolvedColorWithTraitCollection:
[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]];
UIImage *darkImage =
[[self.iconDrawer draw:iconImage
imageColor:darkColor
backgroundColor:darkBackgroundColor
size:iconSize
cornerRadius:cornerRadius] imageWithInsets:buttonOptions.iconInsets.UIEdgeInsets];
UIImage *lightImage =
[[self.iconDrawer draw:iconImage
imageColor:lightColor
backgroundColor:lightBackgroundColor
size:iconSize
cornerRadius:cornerRadius] imageWithInsets:buttonOptions.iconInsets.UIEdgeInsets];
[lightImage.imageAsset
registerImage:darkImage
withTraitCollection:[UITraitCollection
traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]];

return lightImage;
}

Expand Down
1 change: 1 addition & 0 deletions lib/ios/RNNFontAttributesCreator.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ + (NSDictionary *)createFromDictionary:(NSDictionary *)attributesDictionary
style:nil
variant:nil
scaleMultiplier:1.0];
titleTextAttributes[NSParagraphStyleAttributeName] = NSParagraphStyle.defaultParagraphStyle;

return titleTextAttributes;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNIconCreator.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "RNNBaseIconCreator.h"
#import "RNNButtonOptions.h"
#import "RNNIconDrawer.h"
#import <Foundation/Foundation.h>
#import "RNNBaseIconCreator.h"

@interface RNNIconCreator : RNNBaseIconCreator

Expand Down
11 changes: 6 additions & 5 deletions lib/ios/RNNIconCreator.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ - (UIImage *)createIcon:(RNNButtonOptions *)buttonOptions
UIImage *iconImage = buttonOptions.icon.get;
CGSize iconSize = [self resolveIconSize:buttonOptions];
CGFloat cornerRadius = [buttonOptions.iconBackground.cornerRadius withDefault:@(0)].floatValue;
return [[self.iconDrawer draw:iconImage
imageColor:tintColor
backgroundColor:backgroundColor
size:iconSize
cornerRadius:cornerRadius] imageWithInsets:buttonOptions.iconInsets.UIEdgeInsets];
return
[[self.iconDrawer draw:iconImage
imageColor:tintColor
backgroundColor:backgroundColor
size:iconSize
cornerRadius:cornerRadius] imageWithInsets:buttonOptions.iconInsets.UIEdgeInsets];
}

@end
10 changes: 0 additions & 10 deletions lib/ios/RNNLayoutManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ - (UIViewController *)findChildComponentForParent:(UIViewController *)parentView
}
}

if ([parentViewController respondsToSelector:@selector(pendingChildViewControllers)]) {
NSArray *pendingChildVCs = [parentViewController pendingChildViewControllers];
for (UIViewController *childVC in pendingChildVCs) {
UIViewController *result = [self findChildComponentForParent:childVC forId:componentId];
if (result) {
return result;
}
}
}

return nil;
}

Expand Down

0 comments on commit dcff945

Please sign in to comment.