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

[Android] Style with alignText property "right" error #2702

Closed
mrKlar opened this issue Sep 15, 2015 · 12 comments
Closed

[Android] Style with alignText property "right" error #2702

mrKlar opened this issue Sep 15, 2015 · 12 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@mrKlar
Copy link

mrKlar commented Sep 15, 2015

When using a style property of textAlign: "right", I get the following error on Android. It is working in iOS.

screen shot 2015-09-14 at 11 08 23 pm

@ide
Copy link
Contributor

ide commented Sep 15, 2015

cc @mkonicek I can repro this with center alignment too.

@ide ide added the Android label Sep 15, 2015
@brentvatne brentvatne changed the title Android: Style with alignText property "right" error [Android] Style with alignText property "right" error Sep 15, 2015
@kmagiera
Copy link
Contributor

This is for TextInput right? According to the docs textAlign is android only http://facebook.github.io/react-native/docs/textinput.html#content (there is a typo in platform annotation)
Allowed values are: 'start', 'center', 'end'
So the error you're getting is not a good description of the actual problem but you essentially are providing invalid value for that property (flow should be able to catch this earlier as prop type is annotated)

@ide
Copy link
Contributor

ide commented Sep 15, 2015

@kmagiera I encountered this error in a Text component where textAlign works on iOS. The problem is that when you write <Text style={{textAlign: 'center'}}>, "center" is not converted to an enum before sending it to Java.

@kmagiera
Copy link
Contributor

there is discrepancy in the way we handle this for Text and InputText. For Text we just use strings on android so there is no need for the value to be converted. For InputText we use enum and we send number over the bridge. Redbox here is caused by native code trying to read number while string is provided. Are you also getting a redbox because of that with Text component, if so can you send a stacktrace?

@ide
Copy link
Contributor

ide commented Sep 15, 2015

@kmagiera oh you're right. this was a TextInput component (textAlign: center does work on iOS though).

@sowdri
Copy link

sowdri commented Sep 27, 2015

Is there any workaround for this?

@kmagiera
Copy link
Contributor

Just use allowed values: 'center', 'start' or 'end'
see http://facebook.github.io/react-native/docs/textinput.html#content

@mrKlar
Copy link
Author

mrKlar commented Oct 4, 2015

screen shot 2015-10-04 at 3 06 09 pm

Hi still get an error, here are my dependencies

"dependencies": {
"react-native": "^0.11.4",
"react-native-custom-actsheet": "0.0.4",
"react-native-popover": "^0.2.0",
"react-native-responsive-image": "^1.0.0",
"numeral": "^1.5.3",
"react-native-i18n-complete":"^0.1.2"
}

@mrKlar
Copy link
Author

mrKlar commented Nov 8, 2015

I got it to work... BUT, my error is that I was trying to use the property in the CSS. It does not work there, you must use it as an attribute of TextInput directly. Home it is going to work in CSS someday.

@theoriginalgri
Copy link

Interestingly this also affects iOS somehow.

My code is:

  render() {
    var textAlign = Platform.OS == 'ios' ? 'right' : 'end';
    return (
        <TextInput textAlign={textAlign} ref='input' />
    );
  }

This works well (but feels wrong) on both platforms but iOS presents a warning:

2015-12-09 12:52:27.062 [warn][tid:com.facebook.React.JavaScript] 'Warning: Failed propType: Invalid prop `textAlign` of value `right` supplied to `TextInput`, expected one of ["start","center","end"]. Check the render method of `TestComponent`.'

If the value is changed to 'end' for iOS, too, RN 0.16.0 throws an exception:

Invalid NSTextAlignment 'end'. should be one of: (auto, center, justify, left, right)

@kmagiera
Copy link
Contributor

kmagiera commented Dec 9, 2015

@theoriginalgri this issue should be solved by #4481

On iOS at the moment you should st textAlign as a pat of style property

@kmagiera
Copy link
Contributor

kmagiera commented Dec 9, 2015

And the end goal is to unify that for android too, so after #4481 is merged we should only use textAlign as a part of style map as opposed to passing it as a component property directly

@ghost ghost closed this as completed in f453e14 Jan 21, 2016
mkonicek pushed a commit that referenced this issue Jan 29, 2016
Summary:
change `setTextAlign` and `setTextAlignVertical` to receive argument of type `String` (the same as in `StyleSheet`), so that native props and stylesheet props are calling the same ReactMethod

- add demo (may not be necessary)
Closes #4481

Reviewed By: svcscm

Differential Revision: D2823456

Pulled By: mkonicek

fb-gh-sync-id: 349d17549f419b5bdc001d70b583423ade06bfe8
rozele referenced this issue in microsoft/react-native-windows May 25, 2016
Summary:
change `setTextAlign` and `setTextAlignVertical` to receive argument of type `String` (the same as in `StyleSheet`), so that native props and stylesheet props are calling the same ReactMethod

- add demo (may not be necessary)
Closes facebook/react-native#4481

Reviewed By: svcscm

Differential Revision: D2823456

Pulled By: mkonicek

fb-gh-sync-id: 349d17549f419b5bdc001d70b583423ade06bfe8
@facebook facebook locked as resolved and limited conversation to collaborators Jul 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 21, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

6 participants