diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/NavigationWindowProxy.java b/android/modules/ui/src/java/ti/modules/titanium/ui/NavigationWindowProxy.java index d343b764bf1..90b1eb49674 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/NavigationWindowProxy.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/NavigationWindowProxy.java @@ -1,11 +1,12 @@ /** * Appcelerator Titanium Mobile - * Copyright (c) 2018 by Axway, Inc. All Rights Reserved. + * Copyright (c) 2018-2021 by Axway, Inc. All Rights Reserved. * Licensed under the terms of the Apache Public License * Please see the LICENSE included with this distribution for details. */ package ti.modules.titanium.ui; +import org.appcelerator.kroll.KrollPromise; import org.appcelerator.kroll.annotations.Kroll; import org.appcelerator.titanium.TiC; import org.appcelerator.titanium.proxy.TiWindowProxy; @@ -27,7 +28,7 @@ public NavigationWindowProxy() @Override @Kroll.method - public void open(@Kroll.argument(optional = true) Object arg) + public KrollPromise open(@Kroll.argument(optional = true) Object arg) { // FIXME: Shouldn't this complain/blow up if window isn't specified? if (!opened && getProperties().containsKeyAndNotNull(TiC.PROPERTY_WINDOW)) { @@ -37,9 +38,11 @@ public void open(@Kroll.argument(optional = true) Object arg) openWindow(rootView, arg); fireEvent(TiC.EVENT_OPEN, null); } - return; + return KrollPromise.create((promise) -> { + promise.resolve(null); + }); } - super.open(arg); + return super.open(arg); } @Kroll.method diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/WindowProxy.java b/android/modules/ui/src/java/ti/modules/titanium/ui/WindowProxy.java index 0070b0c9fa8..95925638856 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/WindowProxy.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/WindowProxy.java @@ -1,6 +1,6 @@ /** * Appcelerator Titanium Mobile - * Copyright (c) 2013 by Appcelerator, Inc. All Rights Reserved. + * Copyright (c) 2013-2021 by Appcelerator, Inc. All Rights Reserved. * Licensed under the terms of the Apache Public License * Please see the LICENSE included with this distribution for details. */ @@ -11,6 +11,7 @@ import java.util.HashMap; import org.appcelerator.kroll.KrollDict; +import org.appcelerator.kroll.KrollPromise; import org.appcelerator.kroll.annotations.Kroll; import org.appcelerator.kroll.common.Log; import org.appcelerator.titanium.TiActivity; @@ -105,7 +106,7 @@ public TiUIView createView(Activity activity) } @Override - public void open(@Kroll.argument(optional = true) Object arg) + public KrollPromise open(@Kroll.argument(optional = true) Object arg) { HashMap option = null; if (arg instanceof HashMap) { @@ -127,7 +128,7 @@ public void open(@Kroll.argument(optional = true) Object arg) properties.remove(TiC.PROPERTY_BOTTOM); properties.remove(TiC.PROPERTY_LEFT); properties.remove(TiC.PROPERTY_RIGHT); - super.open(arg); + return super.open(arg); } @Override diff --git a/android/titanium/src/java/org/appcelerator/titanium/proxy/TiWindowProxy.java b/android/titanium/src/java/org/appcelerator/titanium/proxy/TiWindowProxy.java index 525a795bc98..1d02fb77693 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/proxy/TiWindowProxy.java +++ b/android/titanium/src/java/org/appcelerator/titanium/proxy/TiWindowProxy.java @@ -1,6 +1,6 @@ /** * Appcelerator Titanium Mobile - * Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved. + * Copyright (c) 2009-2021 by Appcelerator, Inc. All Rights Reserved. * Licensed under the terms of the Apache Public License * Please see the LICENSE included with this distribution for details. */ @@ -12,6 +12,7 @@ import java.util.List; import org.appcelerator.kroll.KrollDict; +import org.appcelerator.kroll.KrollPromise; import org.appcelerator.kroll.KrollProxy; import org.appcelerator.kroll.annotations.Kroll; import org.appcelerator.kroll.common.Log; @@ -72,6 +73,7 @@ public abstract class TiWindowProxy extends TiViewProxy protected boolean windowActivityCreated = false; protected List> sharedElementPairs; public TiWindowProxy navigationWindow; + private KrollPromise openPromise; public interface PostOpenListener { void onPostOpen(TiWindowProxy window); @@ -98,34 +100,39 @@ public TiUIView createView(Activity activity) @Kroll.method @SuppressWarnings("unchecked") - public void open(@Kroll.argument(optional = true) Object arg) + public KrollPromise open(@Kroll.argument(optional = true) Object arg) { if (opened || opening) { - return; + return KrollPromise.create((promise) -> { + promise.reject(new Throwable("Window is already opened or opening.")); + }); } - waitingForOpen = new WeakReference(this); - opening = true; - KrollDict options = null; - TiAnimation animation = null; + openPromise = KrollPromise.create((promise) -> { + waitingForOpen = new WeakReference(this); + opening = true; + KrollDict options = null; + TiAnimation animation = null; - if (arg != null) { - if (arg instanceof KrollDict) { - options = (KrollDict) arg; + if (arg != null) { + if (arg instanceof KrollDict) { + options = (KrollDict) arg; - } else if (arg instanceof HashMap) { - options = new KrollDict((HashMap) arg); + } else if (arg instanceof HashMap) { + options = new KrollDict((HashMap) arg); - } else if (arg instanceof TiAnimation) { + } else if (arg instanceof TiAnimation) { + options = new KrollDict(); + options.put("_anim", animation); + } + + } else { options = new KrollDict(); - options.put("_anim", animation); } - } else { - options = new KrollDict(); - } - - handleOpen(options); + handleOpen(options); + }); + return openPromise; } @Kroll.getProperty(name = "closed") @@ -505,6 +512,11 @@ public void run() if (nativeView != null) { nativeView.postInvalidate(); } + + if (openPromise != null) { + openPromise.resolve(null); + openPromise = null; + } } protected void fillIntent(Activity activity, Intent intent) diff --git a/common/Resources/ti.internal/extensions/ti/ui/tabgroup.js b/common/Resources/ti.internal/extensions/ti/ui/tabgroup.js index e6848155ca2..ba7423877f3 100644 --- a/common/Resources/ti.internal/extensions/ti/ui/tabgroup.js +++ b/common/Resources/ti.internal/extensions/ti/ui/tabgroup.js @@ -75,7 +75,7 @@ if (OS_ANDROID) { TabGroup.prototype.open = function (options) { if (this.currentState === this.state.opened) { - return; + return Promise.reject(new Error('Window is already opened or opening.')); } this.currentState = this.state.opening; @@ -104,9 +104,10 @@ if (OS_ANDROID) { if (this._activeTab !== -1) { this.setActiveTab(this._activeTab); } - _open.call(this, options); + const result = _open.call(this, options); this.currentState = this.state.opened; + return result; }; const _addTab = TabGroup.prototype.addTab; diff --git a/common/Resources/ti.internal/extensions/ti/ui/window.js b/common/Resources/ti.internal/extensions/ti/ui/window.js index 275ddb7796c..9d27c8d974d 100644 --- a/common/Resources/ti.internal/extensions/ti/ui/window.js +++ b/common/Resources/ti.internal/extensions/ti/ui/window.js @@ -63,7 +63,7 @@ if (OS_ANDROID) { } }); - _open.call(this, options); + return _open.call(this, options); }; const _add = Window.prototype.add;