UI FeedBack

Vibration

Vibration enables haptics enhance interactions and convey useful information to users through the sense of touch. Haptic effect simulates physical vibrates when an action triggered. On iOS vibrate which has three level as high, medium and low works on only on iPhone7 and above. Android Vibration Effect's time can be managed depending given value.

JavaScript
JavaScript
const System = require("sf-core/device/system");
const Page = require("sf-core/ui/page");
const extend = require("js-base/core/extend");
const FlexLayout = require('sf-core/ui/flexlayout');
const Color = require('sf-core/ui/color');
const Button = require('sf-core/ui/button');
const Invocation = require('sf-core/util').Invocation;
var Page1 = extend(Page)(
function(_super) {
_super(this, {
onShow: function(params) {
Application.statusBar.visible = false;
this.headerBar.visible = false;
}
});
this.layout.flexDirection = FlexLayout.FlexDirection.ROW;
this.layout.justifyContent = FlexLayout.JustifyContent.CENTER;
this.layout.alignItems = FlexLayout.AlignItems.CENTER;
var myButton = new Button({
width: 100,
height: 50,
text: "Vibrate",
textColor: Color.BLACK,
backgroundColor: Color.create("#00A1F1"),
onPress: function() {
//Android
if (System.OS == "Android") {
System.vibrate({ millisecond: 50 });
}
//iOS
if (System.OS == "iOS") {
var feedbackAlloc = Invocation.invokeClassMethod("UIImpactFeedbackGenerator","alloc",[],"id");
// 0: Light , 1: Medium , 2: Heavy
var argStyle = new Invocation.Argument({
type:"NSInteger",
value: 0
});
var feedbackGenerator = Invocation.invokeInstanceMethod(feedbackAlloc,"initWithStyle:",[argStyle],"NSObject");
Invocation.invokeInstanceMethod(feedbackGenerator,"prepare",[]);
Invocation.invokeInstanceMethod(feedbackGenerator,"impactOccurred",[]);
feedbackGenerator = undefined;
feedbackAlloc = undefined;
}
}
});
this.layout.addChild(myButton);
}
);
module.exports = Page1;

Using Vibrate Effect With Notifications

When a notification is received vibrate effect can be used all the way.

JavaScript
JavaScript
Notifications.onNotificationReceive = function(e) {
//Android
if (System.OS === "Android") {
System.vibrate({ millisecond: 50 });
}
//iOS
if (System.OS === "iOS") {
var feedbackAlloc = Invocation.invokeClassMethod("UIImpactFeedbackGenerator", "alloc", [], "id");
// 0: Light , 1: Medium , 2: Heavy
var argStyle = new Invocation.Argument({
type: "NSInteger",
value: 0
});
var feedbackGenerator = Invocation.invokeInstanceMethod(feedbackAlloc, "initWithStyle:", [argStyle], "NSObject");
Invocation.invokeInstanceMethod(feedbackGenerator, "prepare", []);
Invocation.invokeInstanceMethod(feedbackGenerator, "impactOccurred", []);
feedbackGenerator = undefined;
feedbackAlloc = undefined;
}
}