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

[TIMOB-19919] separates event and callback for onBackPressed #6859

Merged
merged 3 commits into from
Jan 5, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -689,13 +689,18 @@ public void onBackPressed()

TiWindowProxy topWindow = topWindowOnStack();

// Prevent default Android behavior for "back" press
// if the top window has a listener to handle the event.
if (topWindow != null && topWindow.hasListeners(TiC.EVENT_ANDROID_BACK)) {
topWindow.fireEvent(TiC.EVENT_ANDROID_BACK, null);

}

// Override default Android behavior for "back" press
// if the top window has a callback to handle the event.
if (topWindow != null && topWindow.hasProperty(TiC.PROPERTY_ON_BACK)) {
KrollFunction onBackCallback = (KrollFunction) topWindow.getProperty(TiC.PROPERTY_ON_BACK);
onBackCallback.callAsync(activityProxy.getKrollObject(), new Object[] {});

} else {
// If event is not handled by any listeners allow default behavior.
// If event is not handled by custom callback allow default behavior.
super.onBackPressed();
}
}
Expand Down
7 changes: 6 additions & 1 deletion android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,12 @@ public class TiC
* @module.api
*/
public static final String PROPERTY_OKID = "okid";


/**
* @module.api
*/
public static final String PROPERTY_ON_BACK = "onBack";

/**
* @module.api
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
@Kroll.proxy(propertyAccessors={
TiC.PROPERTY_EXIT_ON_CLOSE,
TiC.PROPERTY_FULLSCREEN,
TiC.PROPERTY_ON_BACK,
TiC.PROPERTY_TITLE,
TiC.PROPERTY_TITLEID,
TiC.PROPERTY_WINDOW_SOFT_INPUT_MODE
Expand Down
22 changes: 10 additions & 12 deletions apidoc/Titanium/UI/Window.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,6 @@ events:
This event is fired when the current window's activity detects
a back button press by the user to navigate back.

By default this event would trigger the current activity to be finished
and removed from the task stack. Subscribing to this event with a listener
will prevent the default behavior. To finish the activity from your listener
just call the *close* method of the window.

This event replaces the android:back event. Some behavior
changes may exist such as the event no longer firing when the
user dismisses the keyboard with the back button or when the
user closes a full-screen video which is embedded in a web view
with the back button.

since: '3.0.0'

- name: androidcamera
Expand Down Expand Up @@ -517,7 +506,16 @@ properties:
`backgroundColor` property as well, unless you want the window to be completely
transparent.
type: Number


- name: onBack
summary: |
Callback function that overrides the default behavior when the user presses the **Back**
button.
description: |
This was separated from the <Ti.UI.Window.androidback> event. You need to define this
callback if you explicitly want to override the back button behavior.
type: Callback<Object>

- name: orientationModes
summary: |
Array of supported orientation modes, specified using the orientation
Expand Down