-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
ReactEditText extends AppCompatEditText #23322
Conversation
Generated by 🚫 dangerJS |
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.
@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
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.
Thank you!
@cpojer is there anything I can help with? |
I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification. |
You may want to test this with old Android OS like API 19. Earlier I found some AppCompat widgets wrap the original context, making any
I see couple dangerous See #22885 (comment) was fixed in 58437cd In some of these PRs you may need to do something similar or find better way to keep hold of context. |
@hey99xx We cannot stick to platform widgets forever, even they are getting deprecated. What would be a generic solution for this? |
@hey99xx quick google search reveals that it can be solved if we extend AppCompatActivity. So I think it'll gone once 0.59 released with ReactActivity extending AppCompatActivity. Is that true? |
I dont know why activity class matters for casting context. In support library code that wraps the context with TintContextWrapper only api version is checked, not activity type. I have two suggestion for you: (1) We can either have a generic method that does the context unwrapping done in 58437cd like
then when we need to get the context @Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
- ReactContext reactContext = (ReactContext) getContext();
+ ReactContext reactContext = ReactContextHelper.getReactContext(this); (2) or we save the ReactContext as variable when we know it'll be used again: +final ReactContext mReactContext;
-public ReactEditText(Context context) {
- super(context);
+public ReactEditText(ReactContext context) {
+ super(context);
+ mReactContext = context; @Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
- ReactContext reactContext = (ReactContext) getContext();
InputConnection inputConnection = super.onCreateInputConnection(outAttrs);
if (inputConnection != null && mOnKeyPress) {
- inputConnection = new ReactEditTextInputConnectionWrapper(inputConnection, reactContext, this);
+ inputConnection = new ReactEditTextInputConnectionWrapper(inputConnection, mReactContext, this);
} I prefer 2nd as it's cleaner, and you don't need to worry about which context class wraps which in the future. |
Btw platform widgets like EditText is not getting deprecated. AppCompatEditText is a subclass of EditText that's documented as
As I understand, AppCompat widgets only add value for old Android versions to make app look consistent with modern Android versions, as also mentioned in original checkbox PR #18318. So I support your PRs like this, just make sure you test it :) |
@hey99xx I target M for my current project, because we've been experiencing many issues/inconsistencies on Android versions below. Recently, I found that RN use many APIs that are not available in Android 4.x, and I think the solution might be more use of Support Library. Thank you. |
Aren't setIntrinsicContentSize and onCreateInputConnection crash on lower API versions after this? |
Summary: This sync includes the following changes: - **[4de99b3ca](facebook/react@4de99b3ca )**: fix getSnapshot warning when a selector returns NaN ([#23333](facebook/react#23333)) //<OGURA Daiki>// - **[40eaa22d9](facebook/react@40eaa22d9 )**: Remove dependency on Offscreen Fiber updateQueue for React Cache ([#23229](facebook/react#23229)) //<Luna Ruan>// - **[caf6d4707](facebook/react@caf6d4707 )**: Enable enableCache on Test Renderer native ([#23314](facebook/react#23314)) //<David McCabe>// - **[419ccc2b1](facebook/react@419ccc2b1 )**: Land skipUnmountedBoundaries experiment ([#23322](facebook/react#23322)) //<Andrew Clark>// - **[54f785bc5](facebook/react@54f785bc5 )**: Disallow comments as DOM containers for createRoot ([#23321](facebook/react#23321)) //<Andrew Clark>// - **[e9aa9592c](facebook/react@e9aa9592c )**: change ReactBatchConfig.transition //<Luna Ruan>// - **[51c8411d9](facebook/react@51c8411d9 )**: Log a recoverable error whenever hydration fails ([#23319](facebook/react#23319)) //<Andrew Clark>// - **[79ed5e18f](facebook/react@79ed5e18f )**: Delete vestigial RetryAfterError logic ([#23312](facebook/react#23312)) //<Andrew Clark>// - **[80059bb73](facebook/react@80059bb73 )**: Switch to client rendering if root receives update ([#23309](facebook/react#23309)) //<Andrew Clark>// - **[f7f7ed089](facebook/react@f7f7ed089 )**: Allow suspending in the shell during hydration ([#23304](facebook/react#23304)) //<Andrew Clark>// Changelog: [General][Changed] - React Native sync for revisions 27b5699...4de99b3 jest_e2e[run_all_tests] Reviewed By: rickhanlonii Differential Revision: D34399162 fbshipit-source-id: 5c49e2bdcf63eb6a601cfa6a4e4b8f2e1f83e2dd
Summary: This sync includes the following changes: - **[4de99b3ca](facebook/react@4de99b3ca )**: fix getSnapshot warning when a selector returns NaN ([facebook#23333](facebook/react#23333)) //<OGURA Daiki>// - **[40eaa22d9](facebook/react@40eaa22d9 )**: Remove dependency on Offscreen Fiber updateQueue for React Cache ([facebook#23229](facebook/react#23229)) //<Luna Ruan>// - **[caf6d4707](facebook/react@caf6d4707 )**: Enable enableCache on Test Renderer native ([facebook#23314](facebook/react#23314)) //<David McCabe>// - **[419ccc2b1](facebook/react@419ccc2b1 )**: Land skipUnmountedBoundaries experiment ([facebook#23322](facebook/react#23322)) //<Andrew Clark>// - **[54f785bc5](facebook/react@54f785bc5 )**: Disallow comments as DOM containers for createRoot ([facebook#23321](facebook/react#23321)) //<Andrew Clark>// - **[e9aa9592c](facebook/react@e9aa9592c )**: change ReactBatchConfig.transition //<Luna Ruan>// - **[51c8411d9](facebook/react@51c8411d9 )**: Log a recoverable error whenever hydration fails ([facebook#23319](facebook/react#23319)) //<Andrew Clark>// - **[79ed5e18f](facebook/react@79ed5e18f )**: Delete vestigial RetryAfterError logic ([facebook#23312](facebook/react#23312)) //<Andrew Clark>// - **[80059bb73](facebook/react@80059bb73 )**: Switch to client rendering if root receives update ([facebook#23309](facebook/react#23309)) //<Andrew Clark>// - **[f7f7ed089](facebook/react@f7f7ed089 )**: Allow suspending in the shell during hydration ([facebook#23304](facebook/react#23304)) //<Andrew Clark>// Changelog: [General][Changed] - React Native sync for revisions 27b5699...4de99b3 jest_e2e[run_all_tests] Reviewed By: rickhanlonii Differential Revision: D34399162 fbshipit-source-id: 5c49e2bdcf63eb6a601cfa6a4e4b8f2e1f83e2dd
Summary
Google recommends to extend AppCompat widgets, and this PR changes ReactEditText to extend AppCompatEditText.
Changelog
[Android] [Changed] - ReactEditText extends AppCompatEditText
Test Plan
CI is green, and everything works as before.