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

fix(android): prevent error while navigation back after using page tr… #10439

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions packages/core/ui/transition/page-transition.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { getPageStartDefaultsForType, getRectFromProps, SharedTransition, Shared
import { ImageSource } from '../../image-source';
import { ContentView } from '../content-view';
import { GridLayout } from '../layouts/grid-layout';
import { ad } from '../../utils';
import { Screen } from '../../platform';
import { ExpandedEntry } from '../frame/fragment.transitions.android';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can avoid using android-specific path and import module directly from fragment.transitions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@CatchABus I LL look but I am not sure ExpandedEntry is exported outside of android

Copy link
Contributor

Choose a reason for hiding this comment

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

In these cases @farfromrefug it's best to add a stub interface for ExpandedEntry in a fragment.transitions.d.ts to avoid platform specific imports in bundled code like this.

import { android as AndroidUtils } from '../../utils/native-helper';
// import { Image } from '../image';

@NativeClass
Expand Down Expand Up @@ -171,11 +172,19 @@ export class PageTransition extends Transition {
return animationSet;
}

androidFragmentTransactionCallback(fragmentTransaction: androidx.fragment.app.FragmentTransaction, currentEntry: BackstackEntry, newEntry: BackstackEntry) {
androidFragmentTransactionCallback(fragmentTransaction: androidx.fragment.app.FragmentTransaction, currentEntry: ExpandedEntry, newEntry: BackstackEntry) {
const fromPage = currentEntry.resolvedPage;
const toPage = newEntry.resolvedPage;
const newFragment: androidx.fragment.app.Fragment = newEntry.fragment;
const state = SharedTransition.getState(this.id);
if (!state) {
// when navigating transition is set on the currentEntry but never cleaned up
// which means that on a next navigation forward (without transition) and back
// we will go here with an empty state!
currentEntry.transition = null;
return;
}

const pageEnd = state.pageEnd;

//we can't look for presented right now as the toPage might not be loaded
Expand Down Expand Up @@ -277,10 +286,10 @@ function loadViewInBackground(view: View) {
hiddenHost.content = hostView;
hiddenHost.visibility = 'collapse';
hostView.addChild(view);
hiddenHost._setupAsRootView(ad.getApplicationContext());
hiddenHost._setupAsRootView(AndroidUtils.getApplicationContext());
hiddenHost.callLoaded();

ad.getCurrentActivity().addContentView(hiddenHost.android, new android.view.ViewGroup.LayoutParams(0, 0));
AndroidUtils.getCurrentActivity().addContentView(hiddenHost.android, new android.view.ViewGroup.LayoutParams(0, 0));

return {
hiddenHost,
Expand Down