Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26818] iOS: Move application shortcut under Ti.UI.Shortcut to have parity

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2020-08-11T10:59:58.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.1.0
ComponentsiOS
Labelsparity, shortcut
ReporterVijay Singh
AssigneeJoshua Quick
Created2019-02-11T22:50:16.000+0000
Updated2020-08-11T10:59:58.000+0000

Description

iOS has Ti.UI.iOS.ApplicationShortcuts and android has implemented Ti.UI.ShortcutItem for shortcut. To have parity on both platform , it is discussed to move Shortcut APIs under Ti.UI.Shortcut. Following are the decided APIs -
1. var shortcutItem = Ti.UI.createShortcutItem({
     id: String   // Unique identifier
     title: String
     description: String
     icon: String/Number
     data: Dictionary
    })

2. var shortcut = Ti.UI.createShortcut();

3. shortcut.add(Ti.UI.ShortcutItem);

4. shortcut.items -> Array<Ti.UI.ShortcutItem>

5. shortcut.getById(id) -> Ti.UI.ShortcutItem

6. shortcut.staticItems -> Array<Ti.UI.ShortcutItem>

7. shortcut.remove(Ti.UI.ShortcutItem);

8. shortcut.removeAll();

9. Event listener - Ti.UI.Shortcuts.addEventListener('click', listener);  -> Ti.UI.ShortcutItem

Comments

  1. Vijay Singh 2020-05-09

    PR - https://github.com/appcelerator/titanium_mobile/pull/11697
       var shortcut = Ti.UI.createShortcut();
        
       var callback = function (e) {
       	Ti.API.info("click Event of shortcut item Fired");
        	Ti.API.info(e.item.title);
        	Ti.API.info(e.item.description);
        	Ti.API.info(e.item.data);
        	Ti.API.info(e.item.id);
        };
        
       shortcut.addEventListener("click", callback);
       var win = Titanium.UI.createWindow({
       	title: 'Test', backgroundColor: '#fff', layout: "vertical"
       });
       var btn1 = Ti.UI.createButton({
       	top: 50, height: 45, title: "Add Contact Us Application Shortcut"
       });
       win.add(btn1);
       btn1.addEventListener("click", function () {
       	var shortcut = Ti.UI.createShortcut();
        
       	var shortcutItem = Ti.UI.createShortcutItem({
       		id: "contact_us",
       		title: "Contact Us",
       		description: "Tap to reach us",
       		icon: Ti.UI.iOS.SHORTCUT_ICON_TYPE_ADD,
       		// data: {
       		// 	infoKey: "contact_us"
       		// }
       	});
       	shortcut.add(shortcutItem);
       });
       var btn2 = Ti.UI.createButton({
       	top: 10, height: 45, title: "Remove Contact Us Application Shortcut"
       });
       win.add(btn2);
       btn2.addEventListener("click", function () {
       	var shortcut = Ti.UI.createShortcut();
       	var shortcutItem = shortcut.getById('contact_us');
       	if (shortcutItem != null) {
       	   shortcut.remove(shortcutItem);
       	}
       });
       var btn3 = Ti.UI.createButton({
       	top: 10, height: 45, title: "Count Dynamic App Shortcuts"
       });
       win.add(btn3);
       btn3.addEventListener("click", function () {
       	var shortcut = Ti.UI.createShortcut();
       	var shortcuts = shortcut.items;
       	Ti.API.info("Dynamic  Shortcut count:" + shortcuts.length);
       });
       var btn4 = Ti.UI.createButton({
       	top: 10, height: 45, title: "Count Static App Shortcuts"
       });
       win.add(btn4);
       btn4.addEventListener("click", function () {
       	var shortcut = Ti.UI.createShortcut();
       	var shortcuts = shortcut.staticItems;
       	Ti.API.info("Static App Shortcut count:" + shortcuts.length);
       });
       var btn5 = Ti.UI.createButton({
       	top: 10, height: 45, title: "Dynamic Shortcut Exists?"
       });
       win.add(btn5);
       btn5.addEventListener("click", function () {
       	var shortcut = Ti.UI.createShortcut();
       	var shortcutItem = shortcut.getById('contact_us');
       	var msg = (shortcutItem != null) ? "Shortcut exists" : "Sorry isn't there";
       	alert(msg);
       });
       var btn6 = Ti.UI.createButton({
       	top: 10, height:45, title:"Remove All Dynamic Shortcuts"
       });
       win.add(btn6);
       btn6.addEventListener("click", function () {
       	var shortcut = Ti.UI.createShortcut();
       	shortcut.removeAll();
       });
       var btn7 = Ti.UI.createButton({
       	top: 10, height: 45, title: "Get shortcut by identifier contact_us"
       });
       win.add(btn7);
       btn7.addEventListener("click", function () {
       	var shortcut = Ti.UI.createShortcut();
       	var shortcutItem = shortcut.getById('contact_us');
       	if (shortcutItem != null) {
       	    Ti.API.info(shortcutItem.icon);
       		alert(shortcutItem.title);
       	} else {
       		alert('No shortcut exist for given id');
       	}
       });
       win.open();
       
  2. Christopher Williams 2020-07-17

    merged iOS PR to master for 9.1.0 target
  3. Joshua Quick 2020-07-31

    Removed Ti.UI.createShortcut() method and made Ti.UI.Shortcut a module. The same was done on Android via [TIMOB-27889]. PR (master): https://github.com/appcelerator/titanium_mobile/pull/11857
  4. Samir Mohammed 2020-08-04

    FR Passed, waiting on Jenkins build and backport builds.
  5. Christopher Williams 2020-08-10

    re-enabled the tests on Gary's PR, merged it in to master and then merge the "backports" to 9_1_X and 9_3_X
  6. Samir Mohammed 2020-08-11

    *Closing ticket*. Improvement verified in SDK version 9.1.0.v20200810120239, 9.2.0.v20200810085310 and 9.3.0.v20200810090511. *Test and other information can be found at:* https://github.com/appcelerator/titanium_mobile/pull/11856

JSON Source