Skip to content

Add decimal places support for TextInput on iOS#16119

Closed
ywongweb wants to merge 2 commits into
react:masterfrom
ywongweb:master
Closed

Add decimal places support for TextInput on iOS#16119
ywongweb wants to merge 2 commits into
react:masterfrom
ywongweb:master

Conversation

@ywongweb

@ywongweb ywongweb commented Sep 27, 2017

Copy link
Copy Markdown

Currently when we need to limit the number of decimal places in a TextInput (a common use case is 2 decimals for currency) we have to do this via JS. This causes flickers if the user keeps entering after the maximum digits allowed is reached.

This PR adds a decimalPlaces prop to the TextInput component. Similar to the maxLength prop, the logic to restrict the number of decimal places is done on the native side to eliminate any flickering. If set, it will also prevents the user from entering more than 1 decimal mark.

Test Plan

Add a the following code to your project to limit the decimal places to 2.

<TextInput decimalPlaces={2} />

If the user enters 0, it will have no effect on the TextInput.

Android version will come later.

snack demo of the flickering

run this on an actual device
https://snack.expo.io/SyaYbJqsZ

Question:

Should I also add the decimal checking logic to RCTTextView's textInputShouldChangeTextInRange method?

@ywongweb
ywongweb requested a review from shergin as a code owner September 27, 2017 21:03
@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Sep 27, 2017
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ywongweb I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@pull-bot

pull-bot commented Nov 1, 2017

Copy link
Copy Markdown
Warnings
⚠️

📋 Release Notes - This PR appears to be missing Release Notes.

@facebook-github-bot label Needs more information

Attention: @shergin

Generated by 🚫 dangerJS

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ywongweb I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@stale

stale Bot commented Jan 31, 2018

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale Bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 31, 2018
@stale stale Bot closed this Feb 7, 2018
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. Stale There has been a lack of activity on this issue and it may be closed soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants