Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking change] Remove layout.direction #7032

Open
wants to merge 2 commits into
base: v8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public static LayoutOptions parse(Context context, JSONObject json) {
result.componentBackgroundColor = ThemeColour.parse(context, json.optJSONObject("componentBackgroundColor"));
result.topMargin = NumberParser.parse(json, "topMargin");
result.orientation = OrientationOptions.parse(json);
result.direction = LayoutDirection.fromString(json.optString("direction", ""));

return result;
}
Expand All @@ -28,21 +27,18 @@ public static LayoutOptions parse(Context context, JSONObject json) {
public ThemeColour componentBackgroundColor = new NullThemeColour();
public Number topMargin = new NullNumber();
public OrientationOptions orientation = new OrientationOptions();
public LayoutDirection direction = LayoutDirection.DEFAULT;

public void mergeWith(LayoutOptions other) {
if (other.backgroundColor.hasValue()) backgroundColor = other.backgroundColor;
if (other.componentBackgroundColor.hasValue()) componentBackgroundColor = other.componentBackgroundColor;
if (other.topMargin.hasValue()) topMargin = other.topMargin;
if (other.orientation.hasValue()) orientation = other.orientation;
if (other.direction.hasValue()) direction = other.direction;
}

public void mergeWithDefault(LayoutOptions defaultOptions) {
if (!backgroundColor.hasValue()) backgroundColor = defaultOptions.backgroundColor;
if (!componentBackgroundColor.hasValue()) componentBackgroundColor = defaultOptions.componentBackgroundColor;
if (!topMargin.hasValue()) topMargin = defaultOptions.topMargin;
if (!orientation.hasValue()) orientation = defaultOptions.orientation;
if (!direction.hasValue()) direction = defaultOptions.direction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class BottomTabsPresenter(

private fun mergeBottomTabsOptions(options: Options, view: ViewController<*>) {
val bottomTabsOptions = options.bottomTabsOptions
if (options.layout.direction.hasValue()) bottomTabs.setLayoutDirection(options.layout.direction)
if (bottomTabsOptions.preferLargeIcons.hasValue()) bottomTabs.setPreferLargeIcons(bottomTabsOptions.preferLargeIcons.get())
if (bottomTabsOptions.titleDisplayMode.hasValue()) {
bottomTabs.titleState = bottomTabsOptions.titleDisplayMode.toState()
Expand Down Expand Up @@ -140,7 +139,6 @@ class BottomTabsPresenter(

private fun applyBottomTabsOptions(options: Options) {
val bottomTabsOptions = options.bottomTabsOptions
bottomTabs.setLayoutDirection(options.layout.direction)
bottomTabs.setPreferLargeIcons(options.bottomTabsOptions.preferLargeIcons[false])
bottomTabs.titleState = bottomTabsOptions.titleDisplayMode[defaultTitleState]
bottomTabs.setBackgroundColor(bottomTabsOptions.backgroundColor.get(Color.WHITE)!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ private void applyTopBarOptions(Options options, StackController stack, ViewCont
Options withDefault = stack.resolveChildOptions(child).withDefaultOptions(defaultOptions);

topBar.setTestId(topBarOptions.testId.get(""));
topBar.setLayoutDirection(options.layout.direction);
applyStatusBarDrawBehindOptions(topBarOptions, withDefault);
topBar.setElevation(topBarOptions.elevation.get(DEFAULT_ELEVATION));
if (topBarOptions.topMargin.hasValue() && topBar.getLayoutParams() instanceof MarginLayoutParams) {
Expand Down Expand Up @@ -502,7 +501,6 @@ private void mergeTopBarOptions(TopBarOptions resolveOptions, Options toMerge, S
ViewController<?> child) {
TopBarOptions topBarOptions = toMerge.topBar;
final View component = child.getView();
if (toMerge.layout.direction.hasValue()) topBar.setLayoutDirection(toMerge.layout.direction);
if (topBarOptions.height.hasValue()) topBar.setHeight(topBarOptions.height.get());
if (topBarOptions.elevation.hasValue()) topBar.setElevation(topBarOptions.elevation.get());
if (topBarOptions.topMargin.hasValue() && topBar.getLayoutParams() instanceof MarginLayoutParams) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.reactnativenavigation.viewcontrollers.viewcontroller

import android.view.View
import com.facebook.react.ReactInstanceManager
import com.facebook.react.modules.i18nmanager.I18nUtil
import com.reactnativenavigation.options.Options

class LayoutDirectionApplier {
fun apply(root: ViewController<*>, options: Options, instanceManager: ReactInstanceManager) {
if (options.layout.direction.hasValue() && instanceManager.currentReactContext != null) {
root.activity.window.decorView.layoutDirection = options.layout.direction.get()
I18nUtil.getInstance().allowRTL(instanceManager.currentReactContext, options.layout.direction.isRtl)
I18nUtil.getInstance().forceRTL(instanceManager.currentReactContext, options.layout.direction.isRtl)
if (instanceManager.currentReactContext != null) {
if (I18nUtil.getInstance().isRTL(instanceManager.currentReactContext)) {
root.activity.window.decorView.layoutDirection = View.LAYOUT_DIRECTION_RTL
} else {
root.activity.window.decorView.layoutDirection = View.LAYOUT_DIRECTION_LTR
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
import com.reactnativenavigation.R;
import com.reactnativenavigation.options.LayoutDirection;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -118,11 +117,6 @@ public void setSelectedIcon(int index, Drawable icon) {
}
}

public void setLayoutDirection(LayoutDirection direction) {
LinearLayout tabsContainer = findChildByClass(this, LinearLayout.class);
if (tabsContainer != null) tabsContainer.setLayoutDirection(direction.get());
}

private boolean hasItemsAndIsMeasured(int w, int h, int oldw, int oldh) {
return w != 0 && h != 0 && (w != oldw || h != oldh) && getItemsCount() > 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.reactnativenavigation.R;
import com.reactnativenavigation.options.Alignment;
import com.reactnativenavigation.options.FontOptions;
import com.reactnativenavigation.options.LayoutDirection;
import com.reactnativenavigation.options.SubtitleOptions;
import com.reactnativenavigation.options.TitleOptions;
import com.reactnativenavigation.options.params.Number;
Expand Down Expand Up @@ -318,10 +317,6 @@ public void setOverflowButtonColor(int color) {
titleAndButtonsContainer.getLeftButtonBar().setOverflowButtonColor(color);
}

public void setLayoutDirection(LayoutDirection direction) {
titleAndButtonsContainer.setLayoutDirection(direction.get());
}

public void removeRightButton(ButtonController button) {
removeRightButton(button.getButtonIntId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class StackPresenterTest : BaseTest() {
val options = Options()
options.topBar.title.component = component(Alignment.Fill)
uut.applyChildOptions(options, parent, child)

val component = topBar.titleAndButtonsContainer.getComponent()
Assertions.assertThat(component).isEqualTo(reactTitleView)
Mockito.doReturn(100).`when`(reactTitleView).measuredWidth
Expand Down
26 changes: 10 additions & 16 deletions lib/ios/RNNCommandsHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,16 @@ - (void)setRoot:(NSDictionary *)layout
[self assertReady];
RNNAssertMainQueue();

if (_controllerFactory.defaultOptions.layout.direction.hasValue) {
if ([_controllerFactory.defaultOptions.layout.direction.get isEqualToString:@"rtl"]) {
[[RCTI18nUtil sharedInstance] allowRTL:YES];
[[RCTI18nUtil sharedInstance] forceRTL:YES];
[[UIView appearance]
setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
[[UINavigationBar appearance]
setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
} else {
[[RCTI18nUtil sharedInstance] allowRTL:NO];
[[RCTI18nUtil sharedInstance] forceRTL:NO];
[[UIView appearance]
setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
[[UINavigationBar appearance]
setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
}
if ([RCTI18nUtil sharedInstance].isRTL) {
[[UIView appearance]
setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
[[UINavigationBar appearance]
setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
} else {
[[UIView appearance]
setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
[[UINavigationBar appearance]
setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
}

[_modalManager reset];
Expand Down
1 change: 0 additions & 1 deletion lib/ios/RNNLayoutOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

@property(nonatomic, strong) Color *backgroundColor;
@property(nonatomic, strong) Color *componentBackgroundColor;
@property(nonatomic, strong) Text *direction;
@property(nonatomic, strong) id orientation;
@property(nonatomic, strong) Bool *autoHideHomeIndicator;

Expand Down
3 changes: 0 additions & 3 deletions lib/ios/RNNLayoutOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ - (instancetype)initWithDict:(NSDictionary *)dict {
self = [super initWithDict:dict];
self.backgroundColor = [ColorParser parse:dict key:@"backgroundColor"];
self.componentBackgroundColor = [ColorParser parse:dict key:@"componentBackgroundColor"];
self.direction = [TextParser parse:dict key:@"direction"];
self.orientation = dict[@"orientation"];
self.autoHideHomeIndicator = [BoolParser parse:dict key:@"autoHideHomeIndicator"];
return self;
Expand All @@ -19,8 +18,6 @@ - (void)mergeOptions:(RNNLayoutOptions *)options {
self.backgroundColor = options.backgroundColor;
if (options.componentBackgroundColor.hasValue)
self.componentBackgroundColor = options.componentBackgroundColor;
if (options.direction.hasValue)
self.direction = options.direction;
if (options.orientation)
self.orientation = options.orientation;
if (options.autoHideHomeIndicator)
Expand Down
7 changes: 0 additions & 7 deletions lib/src/interfaces/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,6 @@ export interface OptionsLayout {
* #### (Android specific)
*/
topMargin?: number;

/**
* Set language direction.
* only works with DefaultOptions
*/
direction?: 'rtl' | 'ltr' | 'locale';

/**
* Controls the application's preferred home indicator auto-hiding.
* #### (iOS specific)
Expand Down
2 changes: 2 additions & 0 deletions playground/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import addProcessors from './commons/Processors';
import { setDefaultOptions } from './commons/options/Options';
import testIDs from './testIDs';
import Screens from './screens/Screens';
import { I18nManager } from 'react-native';

// @ts-ignore
alert = (title, message) =>
Expand All @@ -18,6 +19,7 @@ alert = (title, message) =>
});

function start() {
I18nManager.allowRTL(true);
registerScreens();
addProcessors();
setDefaultOptions();
Expand Down
1 change: 0 additions & 1 deletion playground/src/commons/options/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const setDefaultOptions = () =>
layout: {
componentBackgroundColor: Colors.background,
orientation: ['portrait'],
direction: 'locale',
},
topBar: {
backButton: { color: Colors.buttonColor },
Expand Down
8 changes: 0 additions & 8 deletions website/docs/api/options-layout.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ Set the layout top margin.
| ------ | -------- | -------- |
| number | No | Android |

### `direction`

Set language direction, only works with DefaultOptions. `locale` is an Android specific option which sets the direction according to the device locale.

| Type | Required | Platform |
| ---------------------------- | -------- | -------- |
| enum('rtl', 'ltr', 'locale') | No | Both |

### `autoHideHomeIndicator`

Controls the application's preferred home indicator auto-hiding.
Expand Down