fix(android): prevent error on navigation back after using page transition (#10439)

This commit is contained in:
farfromrefuge
2024-06-29 01:15:40 +02:00
committed by GitHub
parent 4abcb216da
commit 7036f12b5c
10 changed files with 59 additions and 44 deletions

View File

@ -282,7 +282,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err); reject(err);
}, },
}), }),
getApplicationContext() getApplicationContext(),
); );
} catch (ex) { } catch (ex) {
reject(ex); reject(ex);
@ -305,7 +305,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err); reject(err);
}, },
}), }),
null null,
); );
} catch (ex) { } catch (ex) {
reject(ex); reject(ex);
@ -343,7 +343,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err); reject(err);
}, },
}), }),
null null,
); );
} catch (ex) { } catch (ex) {
reject(ex); reject(ex);
@ -391,7 +391,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err); reject(err);
}, },
}), }),
null null,
); );
} catch (ex) { } catch (ex) {
reject(ex); reject(ex);
@ -429,7 +429,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err); reject(err);
}, },
}), }),
null null,
); );
} catch (ex) { } catch (ex) {
reject(ex); reject(ex);
@ -466,7 +466,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err); reject(err);
}, },
}), }),
null null,
); );
} catch (ex) { } catch (ex) {
reject(ex); reject(ex);
@ -504,7 +504,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err); reject(err);
}, },
}), }),
null null,
); );
} catch (ex) { } catch (ex) {
reject(ex); reject(ex);
@ -550,7 +550,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err); reject(err);
}, },
}), }),
null null,
); );
} catch (ex) { } catch (ex) {
reject(ex); reject(ex);
@ -635,7 +635,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err); reject(err);
}, },
}), }),
null null,
); );
} catch (ex) { } catch (ex) {
reject(ex); reject(ex);
@ -685,7 +685,7 @@ export class FileSystemAccess implements IFileSystemAccess {
reject(err); reject(err);
}, },
}), }),
null null,
); );
} catch (ex) { } catch (ex) {
reject(ex); reject(ex);
@ -986,7 +986,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) { onError(error) {
reject(error); reject(error);
}, },
}) }),
); );
}); });
} }
@ -1019,7 +1019,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) { onError(error) {
reject(error); reject(error);
}, },
}) }),
); );
}); });
} }
@ -1058,7 +1058,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) { onError(error) {
reject(error); reject(error);
}, },
}) }),
); );
}); });
} }
@ -1098,7 +1098,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) { onError(error) {
reject(error); reject(error);
}, },
}) }),
); );
}); });
} }
@ -1137,7 +1137,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) { onError(error) {
reject(error); reject(error);
}, },
}) }),
); );
}); });
} }
@ -1174,7 +1174,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) { onError(error) {
reject(error); reject(error);
}, },
}) }),
); );
}); });
} }
@ -1215,7 +1215,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) { onError(error) {
reject(error); reject(error);
}, },
}) }),
); );
}); });
} }
@ -1254,7 +1254,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) { onError(error) {
reject(error); reject(error);
}, },
}) }),
); );
}); });
} }
@ -1293,7 +1293,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) { onError(error) {
reject(error); reject(error);
}, },
}) }),
); );
}); });
} }
@ -1332,7 +1332,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
onError(error) { onError(error) {
reject(error); reject(error);
}, },
}) }),
); );
}); });
} }

View File

@ -273,7 +273,7 @@ export class ActionBar extends ActionBarBase {
owner._raiseTap(); owner._raiseTap();
} }
}, },
}) }),
); );
} else { } else {
this.nativeViewProtected.setNavigationIcon(null); this.nativeViewProtected.setNavigationIcon(null);
@ -362,7 +362,7 @@ export class ActionBar extends ActionBarBase {
owner._raiseTap(); owner._raiseTap();
} }
}, },
}) }),
); );
} }

View File

@ -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; 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.fontStyle = fontStyle ?? FontStyle.NORMAL;
this.fontWeight = fontWeight ?? FontWeight.NORMAL; this.fontWeight = fontWeight ?? FontWeight.NORMAL;
this.fontScale = fontScale ?? 1; this.fontScale = fontScale ?? 1;

View File

@ -2,14 +2,14 @@ import type { View } from '../core/view';
import { ViewBase } from '../core/view-base'; import { ViewBase } from '../core/view-base';
import { BackstackEntry } from '../frame'; import { BackstackEntry } from '../frame';
import { isNumber } from '../../utils/types'; import { isNumber } from '../../utils/types';
import { FadeTransition } from './fade-transition';
import { Transition } from '.'; 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 { ImageSource } from '../../image-source';
import { ContentView } from '../content-view'; import { ContentView } from '../content-view';
import { GridLayout } from '../layouts/grid-layout'; import { GridLayout } from '../layouts/grid-layout';
import { ad } from '../../utils';
import { Screen } from '../../platform'; import { Screen } from '../../platform';
import { ExpandedEntry } from '../frame/fragment.transitions.android';
import { android as AndroidUtils } from '../../utils/native-helper';
// import { Image } from '../image'; // import { Image } from '../image';
@NativeClass @NativeClass
@ -175,12 +175,20 @@ export class PageTransition extends Transition {
return animationSet; 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 fromPage = currentEntry.resolvedPage;
const toPage = newEntry.resolvedPage; const toPage = newEntry.resolvedPage;
const newFragment: androidx.fragment.app.Fragment = newEntry.fragment; const newFragment: androidx.fragment.app.Fragment = newEntry.fragment;
const state = SharedTransition.getState(this.id); 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 //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" // and thus some views like ListView/Pager... might not have loaded their "children"
@ -281,10 +289,10 @@ function loadViewInBackground(view: View) {
hiddenHost.content = hostView; hiddenHost.content = hostView;
hiddenHost.visibility = 'collapse'; hiddenHost.visibility = 'collapse';
hostView.addChild(view); hostView.addChild(view);
hiddenHost._setupAsRootView(ad.getApplicationContext()); hiddenHost._setupAsRootView(AndroidUtils.getApplicationContext());
hiddenHost.callLoaded(); 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 { return {
hiddenHost, hiddenHost,

View File

@ -18,7 +18,7 @@ export function platformCheck(parent?: string) {
throw new Error(errorMsg); throw new Error(errorMsg);
}, },
} },
); );
} }

View File

@ -12,7 +12,7 @@ interface IReplacementMap {
* @internal * @internal
*/ */
export function getFileReplacementsFromEnv( export function getFileReplacementsFromEnv(
env: IWebpackEnv = _env env: IWebpackEnv = _env,
): IReplacementMap { ): IReplacementMap {
const fileReplacements: IReplacementMap = {}; const fileReplacements: IReplacementMap = {};
@ -50,7 +50,7 @@ export function getFileReplacementsFromEnv(
export function applyFileReplacements( export function applyFileReplacements(
config, config,
fileReplacements: IReplacementMap = getFileReplacementsFromEnv() fileReplacements: IReplacementMap = getFileReplacementsFromEnv(),
) { ) {
Object.entries(fileReplacements).forEach(([_replace, _with]) => { Object.entries(fileReplacements).forEach(([_replace, _with]) => {
// in case we are replacing source files - we'll use aliases // in case we are replacing source files - we'll use aliases

View File

@ -17,7 +17,7 @@ export function error(...data: any): Error {
// we return the error - the caller can throw or ignore // we return the error - the caller can throw or ignore
if (typeof data[0] === 'string') { if (typeof data[0] === 'string') {
return new Error( 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',
); );
} }

View File

@ -14,12 +14,12 @@ import { getProjectFilePath } from './project';
export function addVirtualEntry( export function addVirtualEntry(
config: Config, config: Config,
name: string, name: string,
contents: string contents: string,
): string { ): string {
return addVirtualModule( return addVirtualModule(
config, config,
`__@nativescript_webpack_virtual_entry_${name}__`, `__@nativescript_webpack_virtual_entry_${name}__`,
contents contents,
); );
} }
@ -29,7 +29,7 @@ export function addVirtualEntry(
export function addVirtualModule( export function addVirtualModule(
config: Config, config: Config,
name: string, name: string,
contents: string contents: string,
): string { ): string {
const virtualEntryPath = join(getEntryDirPath(), `${name}`); const virtualEntryPath = join(getEntryDirPath(), `${name}`);
@ -51,7 +51,7 @@ export function addVirtualModule(
// todo: we can remove this special handling once we no longer support v11 // todo: we can remove this special handling once we no longer support v11
if (config.plugins.has('AngularCompilerPlugin')) { if (config.plugins.has('AngularCompilerPlugin')) {
const compatEntryPath = getProjectFilePath( const compatEntryPath = getProjectFilePath(
join('node_modules', '.nativescript', `${name}`) join('node_modules', '.nativescript', `${name}`),
); );
mkdirSync(dirname(compatEntryPath), { recursive: true }); mkdirSync(dirname(compatEntryPath), { recursive: true });
writeFileSync(compatEntryPath, options[virtualEntryPath]); writeFileSync(compatEntryPath, options[virtualEntryPath]);

View File

@ -143,7 +143,7 @@ export function useConfig(config: keyof typeof defaultConfigs | false) {
*/ */
export function chainWebpack( export function chainWebpack(
chainFn: (config: Config, env: IWebpackEnv) => any, chainFn: (config: Config, env: IWebpackEnv) => any,
options?: { order?: number } options?: { order?: number },
) { ) {
webpackChains.push({ webpackChains.push({
order: options?.order || 0, order: options?.order || 0,
@ -160,8 +160,8 @@ export function chainWebpack(
export function mergeWebpack( export function mergeWebpack(
mergeFn: ( mergeFn: (
config: Partial<webpack.Configuration>, config: Partial<webpack.Configuration>,
env: IWebpackEnv env: IWebpackEnv,
) => any | Partial<webpack.Configuration> ) => any | Partial<webpack.Configuration>,
) { ) {
webpackMerges.push(mergeFn); webpackMerges.push(mergeFn);
} }
@ -217,7 +217,7 @@ export function resolveChainableConfig(): Config {
* @param chainableConfig Optional chain config to use. * @param chainableConfig Optional chain config to use.
*/ */
export function resolveConfig( export function resolveConfig(
chainableConfig = resolveChainableConfig() chainableConfig = resolveChainableConfig(),
): webpack.Configuration { ): webpack.Configuration {
if (!hasInitialized) { if (!hasInitialized) {
throw error('resolveConfig() must be called after init()'); throw error('resolveConfig() must be called after init()');