Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ class TabScreenViewManager :
view.iconResourceName = value
}

override fun setOrientation(
view: TabScreen,
value: String?,
) = Unit

companion object {
const val REACT_CLASS = "RNSBottomTabsScreen"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "title":
mViewManager.setTitle(view, value == null ? null : (String) value);
break;
case "orientation":
mViewManager.setOrientation(view, (String) value);
break;
case "iconResourceName":
mViewManager.setIconResourceName(view, value == null ? null : (String) value);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public interface RNSBottomTabsScreenManagerInterface<T extends View> {
void setTabBarItemIconColor(T view, @Nullable Integer value);
void setTabBarItemBadgeBackgroundColor(T view, @Nullable Integer value);
void setTitle(T view, @Nullable String value);
void setOrientation(T view, @Nullable String value);
void setIconResourceName(T view, @Nullable String value);
void setTabBarItemBadgeTextColor(T view, @Nullable Integer value);
void setIconType(T view, @Nullable String value);
Expand Down
58 changes: 58 additions & 0 deletions apps/src/tests/TestBottomTabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import {
} from '../../shared/gamma/containers/bottom-tabs/BottomTabsContainer';
import { Tab1, Tab2, Tab3, Tab4 } from './tabs';
import Colors from '../../shared/styling/Colors';
// import { NavigationContainer, ParamListBase } from '@react-navigation/native';
// import {
// NativeStackNavigationProp,
// createNativeStackNavigator,
// } from '@react-navigation/native-stack';
// import { Button, View } from 'react-native';

enableFreeze(true);

Expand Down Expand Up @@ -53,6 +59,7 @@ const TAB_CONFIGS: TabConfiguration[] = [
tabBarItemIconColor: Colors.RedDark120,
iconResourceName: 'sym_call_missed', // Android specific
title: 'Tab2',
orientation: 'landscape',
},
contentViewRenderFn: Tab2,
},
Expand All @@ -70,6 +77,7 @@ const TAB_CONFIGS: TabConfiguration[] = [
},
iconResourceName: 'sym_action_email', // Android specific
title: 'Tab3',
orientation: 'portrait',
},
contentViewRenderFn: Tab3,
},
Expand All @@ -85,6 +93,7 @@ const TAB_CONFIGS: TabConfiguration[] = [
iconResourceName: 'sym_action_chat', // Android specific
title: 'Tab4',
badgeValue: '',
orientation: 'portrait',
},
contentViewRenderFn: Tab4,
},
Expand All @@ -107,3 +116,52 @@ function App() {
}

export default App;

// type RouteParamList = {
// Auth: undefined;
// Tabs: undefined;
// };

// type NavigationProp<ParamList extends ParamListBase> = {
// navigation: NativeStackNavigationProp<ParamList>;
// };

// type StackNavigationProp = NavigationProp<RouteParamList>;

// const Stack = createNativeStackNavigator<RouteParamList>();

// function AuthScreen({ navigation }: StackNavigationProp) {
// return (
// <View
// style={{
// flex: 1,
// alignItems: 'center',
// justifyContent: 'center',
// }}>
// <Button title="Log in" onPress={() => navigation.push('Tabs')} />
// </View>
// );
// }

// function WrappedApp() {
// return (
// <NavigationContainer>
// <Stack.Navigator>
// <Stack.Screen
// name="Auth"
// component={AuthScreen}
// // options={{
// // orientation: 'landscape',
// // }}
// />
// <Stack.Screen
// name="Tabs"
// component={App}
// options={{ orientation: 'landscape' }}
// />
// </Stack.Navigator>
// </NavigationContainer>
// );
// }

// export default WrappedApp;
3 changes: 2 additions & 1 deletion apps/src/tests/TestBottomTabs/tabs/Tab4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ export function Tab4() {
<Stack.Screen
name="Screen1"
component={Screen1}
options={{ headerTransparent: true }}
options={{ headerTransparent: true, orientation: 'landscape' }}
/>
<Stack.Screen
name="Screen2"
component={Screen2}
options={{
headerLargeTitle: true,
orientation: 'default',
}}
/>
<Stack.Screen
Expand Down
12 changes: 12 additions & 0 deletions ios/RNSEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,15 @@ typedef NS_ENUM(NSInteger, RNSTabBarMinimizeBehavior) {
RNSTabBarMinimizeBehaviorOnScrollUp,
};
#endif

typedef NS_ENUM(NSInteger, RNSOrientation) {
RNSOrientationInherit,
RNSOrientationAll,
RNSOrientationAllButUpsideDown,
RNSOrientationPortrait,
RNSOrientationPortraitUp,
RNSOrientationPortraitDown,
RNSOrientationLandscape,
RNSOrientationLandscapeLeft,
RNSOrientationLandscapeRight,
};
11 changes: 11 additions & 0 deletions ios/RNSOrientationProviding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#import "RNSEnums.h"

NS_ASSUME_NONNULL_BEGIN

@protocol RNSOrientationProviding

- (RNSOrientation)evaluateOrientation;

@end

NS_ASSUME_NONNULL_END
13 changes: 11 additions & 2 deletions ios/RNSScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#import "RNSScreenContentWrapper.h"
#import "RNSScrollViewBehaviorOverriding.h"

#if !TARGET_OS_TV
#import "RNSOrientationProviding.h"
#endif // !TARGET_OS_TV

#if RCT_NEW_ARCH_ENABLED
#import <React/RCTViewComponentView.h>
#else
Expand Down Expand Up @@ -33,8 +37,13 @@ namespace react = facebook::react;

@class RNSScreenView;

@interface RNSScreen : UIViewController <RNSViewControllerDelegate>

@interface RNSScreen : UIViewController <
RNSViewControllerDelegate
#if !TARGET_OS_TV
,
RNSOrientationProviding
#endif // !TARGET_OS_TV
>
- (instancetype)initWithView:(UIView *)view;
- (UIViewController *)findChildVCForConfigAndTrait:(RNSWindowTrait)trait includingModals:(BOOL)includingModals;
- (BOOL)hasNestedStack;
Expand Down
27 changes: 24 additions & 3 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#import "RNSScreenStackHeaderConfig.h"
#import "RNSTabBarController.h"
#import "RNSScrollViewHelper.h"
#import "RNSConversions.h"

#import "RNSDefines.h"
#import "UIView+RNSUtility.h"
Expand Down Expand Up @@ -1173,19 +1174,19 @@ - (BOOL)shouldOverrideScrollViewContentInsetAdjustmentBehavior
// RNSScreenView does not have a property to control this behavior.
// It looks for parent that conforms to RNSScrollViewBehaviorOverriding to determine
// if it should override ScrollView's behavior.

// As this method is called when RNSScreen willMoveToParentViewController
// and view does not have superView yet, we need to use reactSuperViews.
UIView *parent = [self reactSuperview];

while (parent != nil) {
if ([parent respondsToSelector:@selector(shouldOverrideScrollViewContentInsetAdjustmentBehavior)]) {
id<RNSScrollViewBehaviorOverriding> overrideProvider = static_cast<id<RNSScrollViewBehaviorOverriding>>(parent);
return [overrideProvider shouldOverrideScrollViewContentInsetAdjustmentBehavior];
}
parent = [parent reactSuperview];
}

return NO;
}

Expand Down Expand Up @@ -1981,6 +1982,26 @@ - (void)presentViewController:(UIViewController *)viewControllerToPresent
[super presentViewController:viewControllerToPresent animated:flag completion:completion];
}

#pragma mark - RNSOrientationProviding

#if !TARGET_OS_TV

- (RNSOrientation)evaluateOrientation
{
if ([self.childViewControllers.lastObject respondsToSelector:@selector(evaluateOrientation)]) {
id<RNSOrientationProviding> child = static_cast<id<RNSOrientationProviding>>(self.childViewControllers.lastObject);
RNSOrientation childOrientation = [child evaluateOrientation];

if (childOrientation != RNSOrientationInherit) {
return childOrientation;
}
}

return rnscreens::conversion::RNSOrientationFromUIInterfaceOrientationMask([self supportedInterfaceOrientations]);
}

#endif // !TARGET_OS_TV

#ifdef RCT_NEW_ARCH_ENABLED
#pragma mark - Fabric specific

Expand Down
14 changes: 12 additions & 2 deletions ios/RNSScreenStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@
#import "RNSBottomTabsSpecialEffectsSupporting.h"
#import "RNSScreenContainer.h"

#if !TARGET_OS_TV
#import "RNSOrientationProviding.h"
#endif // !TARGET_OS_TV

NS_ASSUME_NONNULL_BEGIN

@interface RNSNavigationController
: UINavigationController <RNSViewControllerDelegate, RNSBottomTabsSpecialEffectsSupporting>
@interface RNSNavigationController : UINavigationController <
RNSViewControllerDelegate,
RNSBottomTabsSpecialEffectsSupporting
#if !TARGET_OS_TV
,
RNSOrientationProviding
#endif // !TARGET_OS_TV
>

@end

Expand Down
14 changes: 14 additions & 0 deletions ios/RNSScreenStack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ - (UIInterfaceOrientationMask)supportedInterfaceOrientations
return [self topViewController].supportedInterfaceOrientations;
}

#if !TARGET_OS_TV

- (RNSOrientation)evaluateOrientation
{
if ([self.topViewController respondsToSelector:@selector(evaluateOrientation)]) {
id<RNSOrientationProviding> top = static_cast<id<RNSOrientationProviding>>(self.topViewController);
return [top evaluateOrientation];
}

return RNSOrientationInherit;
}

#endif // !TARGET_OS_TV

- (UIViewController *)childViewControllerForHomeIndicatorAutoHidden
{
return [self topViewController];
Expand Down
26 changes: 24 additions & 2 deletions ios/UIViewController+RNScreens.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#import "RNSScreenContainer.h"
#import "UIViewController+RNScreens.h"
#import "RNSOrientationProviding.h"
#import "RNSEnums.h"
#import "RNSConversions.h"

#import <objc/runtime.h>

Expand Down Expand Up @@ -27,8 +30,18 @@ - (UIStatusBarAnimation)reactNativeScreensPreferredStatusBarUpdateAnimation

- (UIInterfaceOrientationMask)reactNativeScreensSupportedInterfaceOrientations
{
UIViewController *childVC = [self findChildRNSScreensViewController];
return childVC ? childVC.supportedInterfaceOrientations : [self reactNativeScreensSupportedInterfaceOrientations];
id<RNSOrientationProviding> childOrientationProvidingVC = [self findChildRNSOrientationProvidingViewController];

if (childOrientationProvidingVC != nil) {
RNSOrientation orientation = [childOrientationProvidingVC evaluateOrientation];
if (orientation == RNSOrientationInherit) {
return [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:self.view.window];
}

return rnscreens::conversion::UIInterfaceOrientationMaskFromRNSOrientation(orientation);
}

return [self reactNativeScreensSupportedInterfaceOrientations];
}

- (UIViewController *)reactNativeScreensChildViewControllerForHomeIndicatorAutoHidden
Expand All @@ -37,6 +50,15 @@ - (UIViewController *)reactNativeScreensChildViewControllerForHomeIndicatorAutoH
return childVC ?: [self reactNativeScreensChildViewControllerForHomeIndicatorAutoHidden];
}

- (id<RNSOrientationProviding>)findChildRNSOrientationProvidingViewController
{
UIViewController *lastViewController = [[self childViewControllers] lastObject];
if ([lastViewController respondsToSelector:@selector(evaluateOrientation)]) {
return static_cast<id<RNSOrientationProviding>>(lastViewController);
}
return nil;
}

- (UIViewController *)findChildRNSScreensViewController
{
UIViewController *lastViewController = [[self childViewControllers] lastObject];
Expand Down
2 changes: 2 additions & 0 deletions ios/bottom-tabs/RCTConvert+RNSBottomTabs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ NS_ASSUME_NONNULL_BEGIN

+ (RNSBottomTabsIconType)RNSBottomTabsIconType:(nonnull id)json;

+ (RNSOrientation)RNSOrientation:(nonnull id)json;

@end

NS_ASSUME_NONNULL_END
Expand Down
16 changes: 16 additions & 0 deletions ios/bottom-tabs/RCTConvert+RNSBottomTabs.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ + (UIOffset)UIOffset:(id)json;
RNSTabBarMinimizeBehaviorAutomatic,
integerValue)

RCT_ENUM_CONVERTER(
RNSOrientation,
(@{
@"inherit" : @(RNSOrientationInherit),
@"all" : @(RNSOrientationAll),
@"allButUpsideDown" : @(RNSOrientationAllButUpsideDown),
@"portrait" : @(RNSOrientationPortrait),
@"portraitUp" : @(RNSOrientationPortraitUp),
@"portraitDown" : @(RNSOrientationPortraitDown),
@"landscape" : @(RNSOrientationLandscape),
@"landscapeLeft" : @(RNSOrientationLandscapeLeft),
@"landscapeRight" : @(RNSOrientationLandscapeRight),
}),
RNSOrientationInherit,
integerValue)

@end

#endif // !RCT_NEW_ARCH_ENABLED
1 change: 1 addition & 0 deletions ios/bottom-tabs/RNSBottomTabsScreenComponentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) UIColor *tabBarItemBadgeBackgroundColor;

@property (nonatomic, nullable) NSString *title;
@property (nonatomic, readonly) RNSOrientation orientation;

@property (nonatomic) BOOL shouldUseRepeatedTabSelectionPopToRootSpecialEffect;
@property (nonatomic) BOOL shouldUseRepeatedTabSelectionScrollToTopSpecialEffect;
Expand Down
Loading
Loading