Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26176] Android: Opening/Closing a dialog should fire a window's blur/focus events (parity)

GitHub Issuen/a
TypeImprovement
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsalert, android, blur, dialog, focus, parity, window
ReporterJoshua Quick
AssigneeJoshua Quick
Created2018-07-02T20:59:00.000+0000
Updated2020-01-14T21:53:26.000+0000

Description

*Summary:* When opening and closing a dialog, the parent window should fire a "blur" and "focus" event respectively. This is to match iOS' behavior. *Steps to reproduce:*

Build and run the below code on Android.

Tap on the "Show Alert" button.

View the Android log. Notice that a "blur" event was not received.

Close the alert dialog.

View the Android log. Notice that a "focus" event was not received.

var window = Ti.UI.createWindow({
	layout: "vertical",
	fullscreen: true,
});
var alertButton = Ti.UI.createButton({
	title: "Show Alert",
	top: "20%",
});
alertButton.addEventListener("click", function(e) {
	// An alert dialog does not trigger window focus/blur events.
	alert("Alert!");
});
window.add(alertButton);
var windowButton = Ti.UI.createButton({
	title: "Show Child Window",
	top: "20%",
});
windowButton.addEventListener("click", function(e) {
	// Displaying a child window does trigger parent window's focus/blur events.
	var childWindow = Ti.UI.createWindow({ backgroundColor: "orange" });
	var closeButton = Ti.UI.createButton({ title: "Close Me" });
	closeButton.addEventListener("click", function(e) {
		childWindow.close();
	});
	childWindow.add(closeButton);
	childWindow.open();
});
window.add(windowButton);
window.addEventListener("focus", function(e) {
	Ti.API.info("@@@ Window 'focus' event received.");
});
window.addEventListener("blur", function(e) {
	Ti.API.info("@@@ Window 'blur' event received.");
});
window.open();
*Expected Result:* Opening a dialog should fire the window's "blur" event. Close a dialog should fire the window's "focus" event. *Notes:* The window's focus/blur events are correctly fired when displaying a child window or when doing a suspend/resume. This is only an issue with displaying dialogs within a window. *Recommended Solution:* Override the Java Activity.onWindowFocusChanged() method. This method will be invoked when opening/closing dialogs and child activities. https://developer.android.com/reference/android/app/Activity.html#onWindowFocusChanged(boolean) We'll need to re-evaluate the focus/blur handling via our TiBaseActivity class' onResume() and onPause() methods since the onWindowFocusChanged() method provides what we need. The current handling is used to handle focus/blur for TabGroup tabs.

Comments

No comments

JSON Source