mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Merge pull request #3391 from NativeScript/issue-3270
Fix: Android platform.screen.mainScreen props are not invalidated aft…
This commit is contained in:
@ -208,7 +208,7 @@ export function test_findFileMatch_with_multiple_matches_loads_by_priority() {
|
||||
}
|
||||
|
||||
function testTemplate(candidates: Array<string>, context: resolver.PlatformContext, expected: string) {
|
||||
var result = resolver.findFileMatch("test", ".xml", candidates, context);
|
||||
var result = resolver._findFileMatch("test", ".xml", candidates, context);
|
||||
TKUnit.assertEqual(result, expected, "File path");
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import * as fileSystemModule from "file-system";
|
||||
import * as styleScopeModule from "ui/styling/style-scope";
|
||||
import * as fileResolverModule from "file-system/file-name-resolver";
|
||||
import * as builderModule from "ui/builder";
|
||||
import * as platformModule from "platform";
|
||||
import "../bundle-entry-points";
|
||||
|
||||
var builder: typeof builderModule;
|
||||
@ -17,6 +18,20 @@ function ensureBuilder() {
|
||||
}
|
||||
}
|
||||
|
||||
var platform: typeof platformModule;
|
||||
function ensurePlatform() {
|
||||
if (!platform) {
|
||||
platform = require("platform");
|
||||
}
|
||||
}
|
||||
|
||||
var fileNameResolver: typeof fileResolverModule;
|
||||
function ensureFileNameResolver() {
|
||||
if (!fileNameResolver) {
|
||||
fileNameResolver = require("file-system/file-name-resolver");
|
||||
}
|
||||
}
|
||||
|
||||
var styleScope: typeof styleScopeModule = undefined;
|
||||
|
||||
var events = new observable.Observable();
|
||||
@ -113,10 +128,10 @@ export function __onLiveSync() {
|
||||
}
|
||||
|
||||
try {
|
||||
var fileResolver: typeof fileResolverModule = require("file-system/file-name-resolver");
|
||||
ensureFileNameResolver();
|
||||
|
||||
// Clear file resolver cache to respect newly added files.
|
||||
fileResolver.clearCache();
|
||||
fileNameResolver.clearCache();
|
||||
|
||||
// Reload app.css in case it was changed.
|
||||
loadCss();
|
||||
@ -136,3 +151,11 @@ export function __onLiveSyncCore() {
|
||||
reloadPage();
|
||||
}
|
||||
global.__onLiveSyncCore = __onLiveSyncCore;
|
||||
|
||||
export function _onOrientationChanged(){
|
||||
ensurePlatform();
|
||||
platform.screen.mainScreen._invalidate();
|
||||
|
||||
ensureFileNameResolver();
|
||||
fileNameResolver._invalidateResolverInstance();
|
||||
}
|
@ -142,6 +142,7 @@ function initComponentCallbacks() {
|
||||
break;
|
||||
}
|
||||
|
||||
appModule._onOrientationChanged();
|
||||
typedExports.notify(<definition.OrientationChangedEventData>{
|
||||
eventName: typedExports.orientationChangedEvent,
|
||||
android: androidApp.nativeApp,
|
||||
|
@ -201,6 +201,7 @@ class IOSApplication implements definition.iOSApplication {
|
||||
break;
|
||||
}
|
||||
|
||||
common._onOrientationChanged();
|
||||
typedExports.notify(<definition.OrientationChangedEventData>{
|
||||
eventName: typedExports.orientationChangedEvent,
|
||||
ios: this,
|
||||
|
@ -17,9 +17,4 @@ declare module "file-system/file-name-resolver" {
|
||||
|
||||
export function resolveFileName(path: string, ext: string): string;
|
||||
export function clearCache(): void;
|
||||
|
||||
//@private
|
||||
export function findFileMatch(path: string, ext: string, candidates: Array<string>, context: PlatformContext): string
|
||||
//@endprivate
|
||||
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
import * as definition from "file-system/file-name-resolver";
|
||||
import * as definition from "file-system/file-name-resolver";
|
||||
import * as fs from "file-system";
|
||||
import * as types from "utils/types";
|
||||
import * as trace from "trace";
|
||||
import * as platform from "platform";
|
||||
import * as appModule from "application";
|
||||
|
||||
declare module "file-system/file-name-resolver" {
|
||||
export function _findFileMatch(path: string, ext: string, candidates: Array<string>, context: PlatformContext): string
|
||||
export function _invalidateResolverInstance(): void;
|
||||
}
|
||||
|
||||
var MIN_WH: string = "minWH";
|
||||
var MIN_W: string = "minW";
|
||||
@ -75,7 +79,7 @@ var minHeightQualifier: QualifierSpec = {
|
||||
}
|
||||
}
|
||||
|
||||
var paltformQualifier: QualifierSpec = {
|
||||
var platformQualifier: QualifierSpec = {
|
||||
isMatch: function (value: string): boolean {
|
||||
return value === "android" ||
|
||||
value === "ios";
|
||||
@ -104,7 +108,7 @@ var supportedQualifiers: Array<QualifierSpec> = [
|
||||
minWidthQualifier,
|
||||
minHeightQualifier,
|
||||
orientationQualifier,
|
||||
paltformQualifier
|
||||
platformQualifier
|
||||
];
|
||||
|
||||
export class FileNameResolver implements definition.FileNameResolver {
|
||||
@ -136,7 +140,7 @@ export class FileNameResolver implements definition.FileNameResolver {
|
||||
ext = "." + ext;
|
||||
|
||||
var candidates = this.getFileCandidatesFromFolder(path, ext);
|
||||
result = findFileMatch(path, ext, candidates, this._context);
|
||||
result = _findFileMatch(path, ext, candidates, this._context);
|
||||
|
||||
if (trace.enabled) {
|
||||
trace.write("Resolved file name for \"" + path + ext + "\" result: " + (result ? result : "no match found"), trace.categories.Navigation);
|
||||
@ -171,7 +175,7 @@ export class FileNameResolver implements definition.FileNameResolver {
|
||||
}
|
||||
}
|
||||
|
||||
export function findFileMatch(path: string, ext: string, candidates: Array<string>, context: definition.PlatformContext): string {
|
||||
export function _findFileMatch(path: string, ext: string, candidates: Array<string>, context: definition.PlatformContext): string {
|
||||
var bestValue = -1
|
||||
var result: string = null;
|
||||
|
||||
@ -226,18 +230,9 @@ function checkQualifier(value: string, context: definition.PlatformContext) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
var appEventAttached: boolean = false;
|
||||
var resolverInstance: FileNameResolver;
|
||||
|
||||
export function resolveFileName(path: string, ext: string): string {
|
||||
if (!appEventAttached) {
|
||||
var app: typeof appModule = require("application");
|
||||
app.on(app.orientationChangedEvent, (data) => {
|
||||
resolverInstance = undefined;
|
||||
});
|
||||
appEventAttached = true;
|
||||
}
|
||||
|
||||
if (!resolverInstance) {
|
||||
resolverInstance = new FileNameResolver({
|
||||
width: platform.screen.mainScreen.widthDIPs,
|
||||
@ -255,3 +250,7 @@ export function clearCache(): void {
|
||||
resolverInstance.clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
export function _invalidateResolverInstance(): void {
|
||||
resolverInstance = undefined;
|
||||
}
|
@ -2,6 +2,12 @@
|
||||
import * as definition from "platform";
|
||||
import * as utils from "utils/utils";
|
||||
|
||||
declare module "platform" {
|
||||
export interface ScreenMetrics {
|
||||
_invalidate(): void;
|
||||
}
|
||||
}
|
||||
|
||||
const MIN_TABLET_PIXELS = 600;
|
||||
|
||||
export module platformNames {
|
||||
@ -100,6 +106,11 @@ class Device implements definition.Device {
|
||||
|
||||
class MainScreen implements definition.ScreenMetrics {
|
||||
private _metrics: android.util.DisplayMetrics;
|
||||
|
||||
public _invalidate(): void {
|
||||
this._metrics = null;
|
||||
}
|
||||
|
||||
private get metrics(): android.util.DisplayMetrics {
|
||||
if (!this._metrics) {
|
||||
this._metrics = new android.util.DisplayMetrics();
|
||||
|
@ -96,6 +96,11 @@ class Device implements definition.Device {
|
||||
|
||||
class MainScreen implements definition.ScreenMetrics {
|
||||
private _screen: UIScreen;
|
||||
|
||||
_invalidate(){
|
||||
//
|
||||
}
|
||||
|
||||
private get screen(): UIScreen {
|
||||
if (!this._screen) {
|
||||
this._screen = utils.ios.getter(UIScreen, UIScreen.mainScreen);
|
||||
|
@ -126,6 +126,11 @@ function pageFromBuilder(moduleNamePath: string, moduleExports: any): Page {
|
||||
}
|
||||
}
|
||||
|
||||
// Attempts to implement https://github.com/NativeScript/NativeScript/issues/1311
|
||||
// if (page && fileName === `${moduleNamePath}.port.xml` || fileName === `${moduleNamePath}.land.xml`){
|
||||
// page["isBiOrientational"] = true;
|
||||
// }
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
@ -200,6 +205,27 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
// Attempts to implement https://github.com/NativeScript/NativeScript/issues/1311
|
||||
// private _subscribedToOrientationChangedEvent = false;
|
||||
// private _onOrientationChanged(){
|
||||
// if (!this._currentEntry){
|
||||
// return;
|
||||
// }
|
||||
|
||||
// let currentPage = this._currentEntry.resolvedPage;
|
||||
// let currentNavigationEntry = this._currentEntry.entry;
|
||||
// if (currentPage["isBiOrientational"] && currentNavigationEntry.moduleName) {
|
||||
// if (this.canGoBack()){
|
||||
// this.goBack();
|
||||
// }
|
||||
// else {
|
||||
// currentNavigationEntry.backstackVisible = false;
|
||||
// }
|
||||
// // Re-navigate to the same page so the other (.port or .land) xml is loaded.
|
||||
// this.navigate(currentNavigationEntry);
|
||||
// }
|
||||
// }
|
||||
|
||||
public navigate(param: any) {
|
||||
if (traceEnabled) {
|
||||
traceWrite(`NAVIGATE`, traceCategories.Navigation);
|
||||
@ -208,6 +234,16 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
|
||||
let entry = buildEntryFromArgs(param);
|
||||
let page = resolvePageFromEntry(entry);
|
||||
|
||||
// Attempts to implement https://github.com/NativeScript/NativeScript/issues/1311
|
||||
// if (page["isBiOrientational"] && entry.moduleName && !this._subscribedToOrientationChangedEvent){
|
||||
// this._subscribedToOrientationChangedEvent = true;
|
||||
// let app = require("application");
|
||||
// if (trace.enabled) {
|
||||
// trace.write(`${this} subscribed to orientationChangedEvent.`, trace.categories.Navigation);
|
||||
// }
|
||||
// app.on(app.orientationChangedEvent, (data) => this._onOrientationChanged());
|
||||
// }
|
||||
|
||||
this._pushInFrameStack();
|
||||
|
||||
let backstackEntry: BackstackEntry = {
|
||||
|
Reference in New Issue
Block a user