-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Simplified AlertIOS #5286
Simplified AlertIOS #5286
Conversation
By analyzing the blame information on this pull request, we identified @tadeuzagallo, @mkonicek and @christopherdro to be potential reviewers. |
I agree that current Alert API is confusing. But this is a very big breaking change, since alert is supposedly used in lots of apps. If we want to introduce a breaking change, we should provide a codemod to migrate old APIs to new one. Also we should change the Android API as well. Thoughts @ide @brentvatne @mkonicek ? |
The only difference between this and the cross-platform Alert API is support for a callback in place of buttons. I can add that to the Android implementation though, I just figured this PR was getting big enough on its own. 😐 And actually the "breaking" part of the change is pretty minor. The most common alert call ( Only the following usages will need to be migrated with this change:
Is there an example of a breaking change with a codemod I could examine to see how to write/integrate that? I could also shim support for the old API for one version with deprecation warnings, which people may be more familiar with. |
edc0b34
to
2e657b8
Compare
@corbt updated the pull request. |
Ok I've updated this to add support for the old API with |
@@ -68,10 +67,9 @@ class Alert { | |||
title: ?string, | |||
message?: ?string, | |||
buttons?: Buttons, | |||
type?: AlertType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was for convenience on iOS. How can people pass the type / style with this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason to change the type
is to switch from an alert to a prompt, and I think it's very unlikely that anyone was using a dialog that appears as a prompt on one platform and an alert on another. But I can add that arg back in with a deprecation warning.
Thanks for working on it! Yup a quick search tells me we have about a dozen files at fb that use |
2e657b8
to
fa7a5c0
Compare
@corbt updated the pull request. |
@mkonicek I've restored support for a |
Thanks for cleaning up the API! Like the new one much better. This is now 100% backwards compatible, correct? |
@mkonicek yes, with deprecation warnings. |
Idea: In places where we've deprecation warnings, we can add a comment |
Nice! If you guys are confident this definitely doesn't break any possible existing call site feel free to comment |
* `style` should be one of 'default', 'cancel' or 'destructive'. | ||
* - **type**: string -- This configures the text input. One of 'plain-text', | ||
* 'secure-text' or 'login-password'. | ||
* - **defaultValue**: string -- the default value for the text field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I like the emphasis for the names but not sure it's a convention in the docs. Check other files. Would rather keep it consistent with docs for other files and then migrate all at once.
fa7a5c0
to
675e12f
Compare
@corbt updated the pull request. |
@mkonicek so as near as I can tell there isn't a great story for documenting function arguments in the RN docs right now. The only API I could find that had anything more formal than a prose definition is LayoutAnimation, which uses the |
Oh but |
675e12f
to
d0f7cfc
Compare
@mkonicek this better? |
@corbt updated the pull request. |
Yup that should render fine :) Looks good, ship it 👍 |
@facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1690217851214564/int_phab to review. |
Summary: Ok, so this started as fixing facebook#5273 but ended up getting a little more complicated. 😄 Currently, AlertIOS has the following API: * `alert(title, message, buttons, type)` * `prompt(title, defaultValue, buttons, callback)` I've changed the API to look like the following: * `alert(title, message, callbackOrButtons)` * `prompt(title, message, callbackOrButtons, type, defaultValue)` I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one: 1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro Closes facebook#5286 Reviewed By: svcscm Differential Revision: D2850400 Pulled By: androidtrunkagent fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
Summary: Ok, so this started as fixing facebook#5273 but ended up getting a little more complicated. 😄 Currently, AlertIOS has the following API: * `alert(title, message, buttons, type)` * `prompt(title, defaultValue, buttons, callback)` I've changed the API to look like the following: * `alert(title, message, callbackOrButtons)` * `prompt(title, message, callbackOrButtons, type, defaultValue)` I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one: 1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro Closes facebook#5286 Reviewed By: svcscm Differential Revision: D2850400 Pulled By: androidtrunkagent fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
Is there a hidden |
@Noitidart I am also looking for the same. have you got solution? |
Ok, so this started as fixing #5273 but ended up getting a little more complicated. 😄
Currently, AlertIOS has the following API:
alert(title, message, buttons, type)
prompt(title, defaultValue, buttons, callback)
I've changed the API to look like the following:
alert(title, message, callbackOrButtons)
prompt(title, message, callbackOrButtons, type, defaultValue)
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
type
is an optional parameter ofalert
. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you useprompt
, but if you want a password input you usealert
with the 'secure-text' type. I've movedtype
toprompt
so all text input is now done withprompt
.alert
is by passing in custom buttons. However,prompt
allows you to pass in a callback that is called when the user clicks the "OK" button, without having to define custom buttons. But, you have to passnull
to either the callback or buttons parameter (can't define both). Since these are mutually exclusive, I've combined them into one parameter and added analogous functionality to bothalert
and theprompt
to make their APIs more consistent.prompt
got broken between 0.16 and 0.17. I've added it back in as an explicit argument (the default value reused themessage
field before, but there are times when you might want both a default value and a message, so they should be separate).Those were all the major changes I made. I did also refactor the UIExplorer a bit to make it more clear what's going on in each example, and updated the documentation for AlertIOS.