Skip to content

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

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

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions packages/core/file-system/file-system-access.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err);
},
}),
getApplicationContext()
getApplicationContext(),
);
} catch (ex) {
reject(ex);
Expand All @@ -305,7 +305,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err);
},
}),
null
null,
);
} catch (ex) {
reject(ex);
Expand Down Expand Up @@ -343,7 +343,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err);
},
}),
null
null,
);
} catch (ex) {
reject(ex);
Expand Down Expand Up @@ -391,7 +391,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err);
},
}),
null
null,
);
} catch (ex) {
reject(ex);
Expand Down Expand Up @@ -429,7 +429,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err);
},
}),
null
null,
);
} catch (ex) {
reject(ex);
Expand Down Expand Up @@ -466,7 +466,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err);
},
}),
null
null,
);
} catch (ex) {
reject(ex);
Expand Down Expand Up @@ -504,7 +504,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err);
},
}),
null
null,
);
} catch (ex) {
reject(ex);
Expand Down Expand Up @@ -550,7 +550,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err);
},
}),
null
null,
);
} catch (ex) {
reject(ex);
Expand Down Expand Up @@ -635,7 +635,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err);
},
}),
null
null,
);
} catch (ex) {
reject(ex);
Expand Down Expand Up @@ -685,7 +685,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err);
},
}),
null
null,
);
} catch (ex) {
reject(ex);
Expand Down Expand Up @@ -986,7 +986,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) {
reject(error);
},
})
}),
);
});
}
Expand Down Expand Up @@ -1019,7 +1019,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) {
reject(error);
},
})
}),
);
});
}
Expand Down Expand Up @@ -1058,7 +1058,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) {
reject(error);
},
})
}),
);
});
}
Expand Down Expand Up @@ -1098,7 +1098,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) {
reject(error);
},
})
}),
);
});
}
Expand Down Expand Up @@ -1137,7 +1137,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) {
reject(error);
},
})
}),
);
});
}
Expand Down Expand Up @@ -1174,7 +1174,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) {
reject(error);
},
})
}),
);
});
}
Expand Down Expand Up @@ -1215,7 +1215,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) {
reject(error);
},
})
}),
);
});
}
Expand Down Expand Up @@ -1254,7 +1254,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) {
reject(error);
},
})
}),
);
});
}
Expand Down Expand Up @@ -1293,7 +1293,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) {
reject(error);
},
})
}),
);
});
}
Expand Down Expand Up @@ -1332,7 +1332,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) {
reject(error);
},
})
}),
);
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/profiling/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function timelineProfileFunctionFactory<F extends Function>(fn: F, name: string,
const end = time();
console.log(`Timeline: Modules: ${name} ${this} (${start}ms. - ${end}ms.)`);
}
}
}
: function () {
const start = time();
try {
Expand All @@ -128,7 +128,7 @@ function timelineProfileFunctionFactory<F extends Function>(fn: F, name: string,
const end = time();
console.log(`Timeline: Modules: ${name} (${start}ms. - ${end}ms.)`);
}
};
};
}

const enum MemberType {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/ui/action-bar/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class ActionBar extends ActionBarBase {
owner._raiseTap();
}
},
})
}),
);
} else {
this.nativeViewProtected.setNavigationIcon(null);
Expand Down Expand Up @@ -362,7 +362,7 @@ export class ActionBar extends ActionBarBase {
owner._raiseTap();
}
},
})
}),
);
}

Expand Down
9 changes: 8 additions & 1 deletion packages/core/ui/styling/font-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ export abstract class Font implements FontDefinition {
return this.fontWeight === FontWeight.SEMI_BOLD || this.fontWeight === FontWeight.BOLD || this.fontWeight === '700' || this.fontWeight === FontWeight.EXTRA_BOLD || this.fontWeight === FontWeight.BLACK;
}

protected constructor(public readonly fontFamily: string, public readonly fontSize: number, fontStyle?: FontStyleType, fontWeight?: FontWeightType, fontScale?: number, public readonly fontVariationSettings?: Array<FontVariationSettingsType>) {
protected constructor(
public readonly fontFamily: string,
public readonly fontSize: number,
fontStyle?: FontStyleType,
fontWeight?: FontWeightType,
fontScale?: number,
public readonly fontVariationSettings?: Array<FontVariationSettingsType>,
) {
this.fontStyle = fontStyle ?? FontStyle.NORMAL;
this.fontWeight = fontWeight ?? FontWeight.NORMAL;
this.fontScale = fontScale ?? 1;
Expand Down
22 changes: 15 additions & 7 deletions packages/core/ui/transition/page-transition.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type { View } from '../core/view';
import { ViewBase } from '../core/view-base';
import { BackstackEntry } from '../frame';
import { isNumber } from '../../utils/types';
import { FadeTransition } from './fade-transition';
import { Transition } from '.';
import { getPageStartDefaultsForType, getRectFromProps, SharedTransition, SharedTransitionAnimationType, SharedTransitionEventData } from './shared-transition';
import { getRectFromProps, SharedTransition, SharedTransitionAnimationType, SharedTransitionEventData } from './shared-transition';
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

@NathanWalker NathanWalker Nov 25, 2023

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 @@ -175,12 +175,20 @@ 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);
const pageEnd = state?.pageEnd;
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
// and thus some views like ListView/Pager... might not have loaded their "children"
Expand Down Expand Up @@ -281,10 +289,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
2 changes: 1 addition & 1 deletion packages/core/utils/platform-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function platformCheck(parent?: string) {

throw new Error(errorMsg);
},
}
},
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/webpack5/src/helpers/fileReplacements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IReplacementMap {
* @internal
*/
export function getFileReplacementsFromEnv(
env: IWebpackEnv = _env
env: IWebpackEnv = _env,
): IReplacementMap {
const fileReplacements: IReplacementMap = {};

Expand Down Expand Up @@ -50,7 +50,7 @@ export function getFileReplacementsFromEnv(

export function applyFileReplacements(
config,
fileReplacements: IReplacementMap = getFileReplacementsFromEnv()
fileReplacements: IReplacementMap = getFileReplacementsFromEnv(),
) {
Object.entries(fileReplacements).forEach(([_replace, _with]) => {
// in case we are replacing source files - we'll use aliases
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack5/src/helpers/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function error(...data: any): Error {
// we return the error - the caller can throw or ignore
if (typeof data[0] === 'string') {
return new Error(
'\n\n[@nativescript/webpack]\n---\n\n' + dedent(data[0]) + '\n\n---\n'
'\n\n[@nativescript/webpack]\n---\n\n' + dedent(data[0]) + '\n\n---\n',
);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/webpack5/src/helpers/virtualModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import { getProjectFilePath } from './project';
export function addVirtualEntry(
config: Config,
name: string,
contents: string
contents: string,
): string {
return addVirtualModule(
config,
`__@nativescript_webpack_virtual_entry_${name}__`,
contents
contents,
);
}

Expand All @@ -29,7 +29,7 @@ export function addVirtualEntry(
export function addVirtualModule(
config: Config,
name: string,
contents: string
contents: string,
): string {
const virtualEntryPath = join(getEntryDirPath(), `${name}`);

Expand All @@ -51,7 +51,7 @@ export function addVirtualModule(
// todo: we can remove this special handling once we no longer support v11
if (config.plugins.has('AngularCompilerPlugin')) {
const compatEntryPath = getProjectFilePath(
join('node_modules', '.nativescript', `${name}`)
join('node_modules', '.nativescript', `${name}`),
);
mkdirSync(dirname(compatEntryPath), { recursive: true });
writeFileSync(compatEntryPath, options[virtualEntryPath]);
Expand Down
8 changes: 4 additions & 4 deletions packages/webpack5/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function useConfig(config: keyof typeof defaultConfigs | false) {
*/
export function chainWebpack(
chainFn: (config: Config, env: IWebpackEnv) => any,
options?: { order?: number }
options?: { order?: number },
) {
webpackChains.push({
order: options?.order || 0,
Expand All @@ -160,8 +160,8 @@ export function chainWebpack(
export function mergeWebpack(
mergeFn: (
config: Partial<webpack.Configuration>,
env: IWebpackEnv
) => any | Partial<webpack.Configuration>
env: IWebpackEnv,
) => any | Partial<webpack.Configuration>,
) {
webpackMerges.push(mergeFn);
}
Expand Down Expand Up @@ -217,7 +217,7 @@ export function resolveChainableConfig(): Config {
* @param chainableConfig Optional chain config to use.
*/
export function resolveConfig(
chainableConfig = resolveChainableConfig()
chainableConfig = resolveChainableConfig(),
): webpack.Configuration {
if (!hasInitialized) {
throw error('resolveConfig() must be called after init()');
Expand Down
Loading