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

[iOS] Fix textAttributes not applied when typing text #23585

Closed
wants to merge 2 commits into from

Conversation

zhongwuzw
Copy link
Contributor

Summary

Currently, if we has defaultValue, textAttributes like letterSpacing can works, but if textinput has not default text, when we typing the text, some attributes not applied.

Changelog

[iOS] [Fixed] - Fix textAttributes not applied when typing text

Test Plan

We can use code like below, letterSpacing not work previously.

<TextInput
  style={{ letterSpacing: 10, color: 'red' }}
  placeholder="I will not respect letterSpacing value on iOS"
/>

Before:
2019-02-22 11_52_07

If we have defaultValue, letterSpacing works:

<TextInput
  style={{ letterSpacing: 10 , color: 'red'}}
  placeholder="I will not respect letterSpacing value on iOS"
  defaultValue="s"
/>

2019-02-22 11_55_01

After:
2019-02-22 11_49_09

@zhongwuzw zhongwuzw requested a review from shergin as a code owner February 22, 2019 03:56
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 22, 2019
Copy link
Contributor

@janicduplessis janicduplessis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some snapshot tests are failling, can you check if its related to this pr and fix those? Probably just need to update them if the changes are expected.

@zhongwuzw
Copy link
Contributor Author

@janicduplessis Thanks for review, I scan the failed tests, seems the failed snapshot tests not related to TextInput, they don't use this module.

So I think it needs to fix by another PR? and TBO 😂 , I don't familiar how to do it, maybe I need remove all snapshot images and re-generate it?

@janicduplessis
Copy link
Contributor

👍 I just double checked and you are right it is for other components. I think you have to use xcode to update the snapshots but I've never done it either haha.

@@ -88,6 +91,20 @@ - (void)setPlaceholderColor:(UIColor *)placeholderColor
_placeholderView.textColor = _placeholderColor ?: defaultPlaceholderColor();
}

- (void)setReactTextAttributes:(RCTTextAttributes *)reactTextAttributes
{
if (!reactTextAttributes.effectiveTextAttributes || [reactTextAttributes isEqual:_reactTextAttributes]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a variable for effectiveTextAttributes to avoid computing it twice, looks like a pretty big getter

- (NSDictionary<NSAttributedStringKey, id> *)effectiveTextAttributes
(I hate properties :))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janicduplessis 👍 I removed !reactTextAttributes.effectiveTextAttributes check because it cannot be nil.

@@ -62,6 +65,20 @@ - (void)setPlaceholderColor:(UIColor *)placeholderColor
[self _updatePlaceholder];
}

- (void)setReactTextAttributes:(RCTTextAttributes *)reactTextAttributes
{
if (!reactTextAttributes.effectiveTextAttributes || [reactTextAttributes isEqual:_reactTextAttributes]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@cpojer
Copy link
Contributor

cpojer commented Feb 25, 2019

@zhongwuzw can you update the screenshot examples?

@zhongwuzw
Copy link
Contributor Author

@cpojer I don't know why here failed 🤔 , seems all other PRs like #23608 #23625 passes. So I don't ensure wether the code has issues, or I just re-generate the snapshots inside this PR? any instructions I can find to re-generate snapshots? I checked the snapshot tests code, seems I only need to remove snapshots

and set _runner.recordMode = YES?

@cpojer
Copy link
Contributor

cpojer commented Feb 25, 2019

Yeah I think that's it.

@janicduplessis
Copy link
Contributor

@zhongwuzw Looks like tests are passing on master, maybe you can just try rebasing see if it fixes it?

[iOS] Fix textAttributes not applied when typing text

Remove dead code
@zhongwuzw zhongwuzw force-pushed the fix_input_textAttributes branch from 4901a12 to ebaa9bb Compare February 25, 2019 05:00
@zhongwuzw
Copy link
Contributor Author

@cpojer @janicduplessis CI passes! 🍻

Copy link
Contributor

@cpojer cpojer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you!

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Feb 25, 2019
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@hramos hramos added the Merged This PR has been merged. label Mar 8, 2019
@react-native-bot react-native-bot removed the Import Started This pull request has been imported. This does not imply the PR has been approved. label Mar 8, 2019
facebook-github-bot pushed a commit that referenced this pull request Sep 17, 2019
Summary:
This diff changes how we apply default text attributes to backed text input.
The original change in #23585 that introduced the `reactTextAttributes` field in for RCTBackedTextInputViewProtocol was great! Thank you Wu zhongwuzw !
However, there is one detail that needs to be changed.
RCTBackedTextInputViewProtocol is designed to only abstract complexity of iOS text input components (UITextView and UITextField); it intentionally does not have any React-specific fields or types. Adding a field `RCTTextAttributes *reactTextAttributes;` violates this principle and make it hard to reuse this functionality in the new Fabric-powered TextInput.

This diff changes the type of this prop from `RCTTextAttributes` to `NSDictionary<NSAttributedStringKey,id> *`  (exact same type that UITextView and UITextField use).

Reviewed By: cpojer

Differential Revision: D17408501

fbshipit-source-id: 65f2bba119ccc30f22e87c28d0f8ea6f731cd365
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants