-
Notifications
You must be signed in to change notification settings - Fork 444
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
Support vibrate(intensity, mode)
for iOS
#1904
Comments
And iOS13+ seems have even more options, I'll test them later |
Add the second param to vibrate method with default value // src/modules/system/wrap_System.cpp
int w_vibrate(lua_State *L)
{
double seconds = luaL_optnumber(L, 1, 0.5);
const char *mode = luaL_optstring(L, 2, "default");
instance()->vibrate(seconds, mode);
return 0;
} And ignore mode param on Android(For now): // src/modules/system/System.cpp
void System::vibrate(double seconds, const std::string &mode) const
{
#ifdef LOVE_ANDROID
love::android::vibrate(seconds);
LOVE_UNUSED(mode);
#elif defined(LOVE_IOS)
love::ios::vibrate(seconds, mode);
#else
LOVE_UNUSED(seconds);
LOVE_UNUSED(mode);
#endif
} Then process them on iOS: void vibrate(const double intensity, const std::string &mode)
{
@autoreleasepool
{
if (mode != "default" && @available(iOS 10.0, *)) {
// iOS 10.0 and above
UIImpactFeedbackGenerator *impact = nil;
if (mode == "light") {
impact = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
} else if (mode == "medium") {
impact = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];
} else if (mode == "heavy") {
impact = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy];
}
if (@available(iOS 13.0, *)) {
// iOS 13.0 and above
if (mode == "soft") {
impact = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleSoft];
} else if (mode == "rigid") {
impact = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleRigid];
}
if(impact != nil){
[impact impactOccurredWithIntensity:(intensity < 0 ? 0 : (intensity > 1 ? 1 : intensity))];
return;
}
}
if(impact != nil){
[impact impactOccurred];
return;
}
}
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
} |
vibrate(seconds)
for iOSvibrate(intensity, mode)
for iOS
Per my comment in the pull request (#1905 (comment)), I don't really feel good about having platform-specific function parameters. I wonder if some of Android's haptic feedback APIs are similar enough to the ones you've investigated for iOS that the two backends can both implement a mode parameter. |
Android actually has similar "light", "medium" and "heavy" haptic feedbacks. Like |
Another solution is continue using simgle |
On
iOS 10.0+
,iPadOS 10.0+
andMac Catalyst 13.1+
, it is possible for iPhones and iPads to generate different type of viberations, Not just a fixed 400ms one. Just Mapping seconds toUIFeedbackGenerator
's subclasses like this:The text was updated successfully, but these errors were encountered: