Last active
March 14, 2017 22:01
-
-
Save nuno/602bc3a8e9ea9cfe6393f5e2b01e9051 to your computer and use it in GitHub Desktop.
iOS 10: Support iPhone 7 Haptic Engine API demo - docs revision
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dataStructure = ["FEEDBACK_GENERATOR_TYPE_SELECTION", "FEEDBACK_GENERATOR_TYPE_IMPACT", "FEEDBACK_GENERATOR_TYPE_NOTIFICATION"]; | |
var win = Ti.UI.createWindow({ | |
backgroundColor: "#fff", | |
title: "iOS 10 Haptic Engine", | |
translucent: false | |
}); | |
var nav = Ti.UI.iOS.createNavigationWindow({ | |
window: win | |
}); | |
var list = Ti.UI.createListView({ | |
sections: | |
[Ti.UI.createListSection({ | |
items: createItems() | |
})] | |
}); | |
list.addEventListener("itemclick", function(e) { | |
var type = e.itemId; | |
var args = { | |
type: Ti.UI.iOS[type] // Same as Ti.UI.iOS.FEEDBACK_GENERATOR_TYPE_SELECTION etc. | |
}; | |
// If we select the impact-feedback, the style property specifies the style of it | |
if (Ti.UI.iOS[type] == Ti.UI.iOS.FEEDBACK_GENERATOR_TYPE_IMPACT) { | |
args["style"] = Ti.UI.iOS.FEEDBACK_GENERATOR_IMPACT_STYLE_MEDIUM; | |
} | |
// Create the generator with the selected type | |
var generator = Ti.UI.iOS.createFeedbackGenerator(args); | |
generator.prepare(); // Prepare the feedback before to avoid latence | |
// Execute different feedbacks based on the type | |
switch (generator.type) { | |
case Ti.UI.iOS.FEEDBACK_GENERATOR_TYPE_SELECTION: | |
generator.selectionChanged(); | |
break; | |
case Ti.UI.iOS.FEEDBACK_GENERATOR_TYPE_IMPACT: | |
generator.impactOccurred(); | |
break; | |
case Ti.UI.iOS.FEEDBACK_GENERATOR_TYPE_NOTIFICATION: | |
generator.notificationOccurred(Ti.UI.iOS.FEEDBACK_GENERATOR_NOTIFICATION_TYPE_SUCCESS); | |
break; | |
} | |
this.deselectItem(e.sectionIndex, e.itemIndex); | |
}); | |
win.add(list); | |
nav.open(); | |
function createItems() { | |
var items = []; | |
for (var i = 0; i < dataStructure.length; i++) { | |
items.push({ | |
properties: { | |
itemId: dataStructure[i], | |
title: dataStructure[i], | |
height: 60, | |
accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_DISCLOSURE | |
} | |
}); | |
} | |
return items; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment