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

feat(android): parity for Tab.popToRootWindow() #13976

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ public void onPropertyChanged(String name, Object value)
}
}

@Kroll.method
public void popToRootWindow()
{
TiApplication.getInstance().popToRootWindow();
}

@Override
public String getApiName()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.json.JSONException;
import org.json.JSONObject;
import ti.modules.titanium.TitaniumModule;
import ti.modules.titanium.ui.TabGroupProxy;

import java.io.File;
import java.lang.Thread.UncaughtExceptionHandler;
Expand Down Expand Up @@ -1004,4 +1005,35 @@ public AccessibilityManager getAccessibilityManager()
public void verifyCustomModules(TiRootActivity rootActivity)
{
}

public void popToRootWindow()
{
/**
* emulates the iOS Tab.popToRootWindow() by closing all windows above a TabGroup.
*/
int tabGroupPosition = -1;
boolean isTabGroup = false;

for (int i = 0; i <= activityStack.size(); ++i) {
isTabGroup = (activityStack.get(i).get() instanceof TiActivity)
&& ((TiActivity) activityStack.get(i).get()).getWindowProxy() instanceof TabGroupProxy;
if (isTabGroup) {
tabGroupPosition = i;
break;
}
}

// no TabGroup - don't do anything
if (!isTabGroup || tabGroupPosition == -1) {
return;
}

// finish all activities above our TabGroup
for (int i = activityStack.size() - 1; i > tabGroupPosition; --i) {
if (activityStack.get(i).get() instanceof TiActivity) {
TiActivity currentActivity = (TiActivity) activityStack.get(i).get();
currentActivity.finish();
m1ga marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
7 changes: 3 additions & 4 deletions apidoc/Titanium/UI/Tab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,18 @@ methods:
notes: Set the value of the [window](Titanium.UI.Tab.window) property directly.

- name: popToRootWindow
# FIXME: I don't think this exists on Android!
summary: Closes all windows that are currently opened inside the tab.
description: Note that only the `close` event of the most recently opened window is fired.
parameters:
- name: options
summary: |
Options supporting a single `animated` boolean property to determine whether the windows
iOS only: Options supporting a single `animated` boolean property to determine whether the windows
will be animated while being closed (default: false).
type: AnimatedOptions
optional: true
default: "{ animated: false }"
since: "6.2.0"
platforms: [iphone, ipad, macos]
since: {android: "12.4.0", iphone: "6.2.0", ipad: "6.2.0", macos: "9.2.0"}
platforms: [android, iphone, ipad, macos]

properties:
- name: active
Expand Down
Loading