-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(android): migrate to support library apis #6129
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
Conversation
vakrilov
left a comment
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.
👍 👍 👍
There are 2 really minor breaking changes in the public APIs. I don't think they should stop this from going in, but we should note them along with the fact that we are switching to support Activity/Fragments:
frame.d.ts:
AndroidActivityCallbacks.onCreateAnimator -> AndroidActivityCallbacks.onCreateAnimation
transition.d.ts:
Transition.createAndroidAnimator -> Transition.createAndroidAnimation
| loadAnimatorMethod = manager.getClass().getDeclaredMethod("loadAnimator", javaClassArray(android.app.Fragment.class, java.lang.Integer.TYPE, java.lang.Boolean.TYPE, java.lang.Integer.TYPE)); | ||
| if (loadAnimatorMethod != null) { | ||
| loadAnimatorMethod.setAccessible(true); | ||
| loadAnimationMethod = manager.getClass().getDeclaredMethod("loadAnimation", javaClassArray(android.support.v4.app.Fragment.class, java.lang.Integer.TYPE, java.lang.Boolean.TYPE, java.lang.Integer.TYPE)); |
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.
Its worth debugging to see it the reflection we are using to get the default animations is still valid.
There is a check ( if (loadAnimationMethod != null)) on the next line that will prevent this code form crashing, nut it might be the case that this method does not exist at all.
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.
Yep, I checked it when I added it -- method's good and the default enter animation is now a fast "push fade" (vs fade previously).
| import { Transition, AndroidTransitionType } from "./transition"; | ||
|
|
||
| //http://developer.android.com/training/animation/cardflip.html | ||
| // http://developer.android.com/training/animation/cardflip.html |
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.
Not sure how much of the code in this tutorial is still relevant as it uses Animators.
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.
I left the link intact to keep the traceability as we are using similar logic (more or less) just with Animation APIs.
|
@vakrilov updated the PR body with the breaking changes section as discussed. |
|
@manoldonev great job! You should mention in my PR that the work is done here. |
|
@farfromrefug thank you for your effort too! |
|
@manoldonev I am just glad it triggered the change! Amazing addition to Nativescript |
|
@manoldonev In a project that is using NativeScript with JavaScript. |
|
@shiv19 reproduced it in a project with nativescript-plugin-firebase. Working on it -- it is somehow related to the version of the support library that is used (maybe related to |
|
About "Note that migrating to support library FragmentManager implies the rather tedious switch from Animators to Animations API as well (as the supportlib manager only works with Animations)" -- on further research it seems this was true only for older versions of the support library (up to ~26?). Newer versions (27.*) provide dual support for animations OR animators. However, due to some legacy code in NativeScript CLI we are mostly forcing the 26.0.0-alpha version of the support library in NativeScript apps (unless a specific plugin changes that). We will try to clean up the CLI and possibly revert the implementation here to use animators again instead of animations. |
Fixes `Error: java.lang.CloneNotSupportedException: Class android.support.v4.app.FragmentManagerImpl$AnimationOrAnimator doesn't implement Cloneable` in specific projects. Related to #5785 Related to #6129 BREAKING CHANGE Before: Default fragment enter animation was Android version specific After: Default fragment enter animation is now fade animation for all Android versions You can customise the transition per navigation entry or globally via the [navigation transitions API]( https://docs.nativescript.org/core-concepts/navigation#navigation-transitions)
Necessary with NativeScript/NativeScript#6129 NOTE: This is not going to be released with {N} 4.2 (currently only in master branch)
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Switch Android Activity/Fragment/FragmentManager to support library APIs (guideline from Google that this is the way to go as they are deprecating framework fragments from Android P onwards).
Note that migrating to support library FragmentManager implies the rather tedious switch from Animators to Animations API as well (as the supportlib manager only works with Animations).(see comments below)This should facilitate/enable future Android work with Material Design, shared element transitions, etc.
Fixes #5785
Related to #5789
BREAKING CHANGE:
NativeScript core framework now extends support library APIs versus native framework classes as per Google's latest guidelines:
android.support.v7.app.AppCompatActivity(vs android.app.Activity)android.support.v4.app.Fragment(vs android.app.Fragment)android.support.v4.app.FragmentManager(vs android.app.FragmentManager)Before:
Custom Android activities extended
android.app.ActivityAfter:
Custom Android activities should extend
android.support.v7.app.AppCompatActivityTo migrate the code of your custom activities follow the example below:
Before:
After:
Before:
Default fragment enter animation was Android version specific
After:
Default fragment enter animation is now fade animation for all Android versions. You can customise the transition per navigation entry or globally via the navigation transitions API
Before:
AndroidFragmentCallbacks interface exposed the following
onCreateAnimator(...)methodAfter:
AndroidFragmentCallbacks interface now exposes the following
onCreateAnimation(...)method instead (andonCreateAnimator(...)is now removed)Before:
Transition class exposed the following abstract
createAndroidAnimator(...)methodAfter:
Transition class now exposes the following abstract
createAndroidAnimation(...)method instead (and `createAndroidAnimation(...) is now removed)To migrate the code of your custom transitions follow the example below:
Before:
After: