Add more haptic feedback varieties (flutter/engine#4699)
* Add more haptic feedback varieties * Make the specific feedback types do nothing on <iOS 10
This commit is contained in:
@@ -48,7 +48,7 @@ public class PlatformPlugin implements MethodCallHandler, ActivityLifecycleListe
|
||||
playSystemSound((String) arguments);
|
||||
result.success(null);
|
||||
} else if (method.equals("HapticFeedback.vibrate")) {
|
||||
vibrateHapticFeedback();
|
||||
vibrateHapticFeedback((String) arguments);
|
||||
result.success(null);
|
||||
} else if (method.equals("SystemChrome.setPreferredOrientations")) {
|
||||
setSystemChromePreferredOrientations((JSONArray) arguments);
|
||||
@@ -85,9 +85,20 @@ public class PlatformPlugin implements MethodCallHandler, ActivityLifecycleListe
|
||||
}
|
||||
}
|
||||
|
||||
private void vibrateHapticFeedback() {
|
||||
private void vibrateHapticFeedback(String feedbackType) {
|
||||
View view = mActivity.getWindow().getDecorView();
|
||||
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
||||
if (feedbackType == null) {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
||||
} else if (feedbackType.equals("HapticFeedbackType.lightImpact")) {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
|
||||
} else if (feedbackType.equals("HapticFeedbackType.mediumImpact")) {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
||||
} else if (feedbackType.equals("HapticFeedbackType.heavyImpact")) {
|
||||
// HapticFeedbackConstants.CONTEXT_CLICK from API level 23.
|
||||
view.performHapticFeedback(6);
|
||||
} else if (feedbackType.equals("HapticFeedbackType.selectionClick")) {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK);
|
||||
}
|
||||
}
|
||||
|
||||
private void setSystemChromePreferredOrientations(JSONArray orientations) throws JSONException {
|
||||
|
||||
@@ -40,7 +40,7 @@ using namespace shell;
|
||||
[self playSystemSound:args];
|
||||
result(nil);
|
||||
} else if ([method isEqualToString:@"HapticFeedback.vibrate"]) {
|
||||
[self vibrateHapticFeedback];
|
||||
[self vibrateHapticFeedback:args];
|
||||
result(nil);
|
||||
} else if ([method isEqualToString:@"SystemChrome.setPreferredOrientations"]) {
|
||||
[self setSystemChromePreferredOrientations:args];
|
||||
@@ -76,8 +76,23 @@ using namespace shell;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)vibrateHapticFeedback {
|
||||
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
||||
- (void)vibrateHapticFeedback:(NSString*)feedbackType {
|
||||
if (!feedbackType) {
|
||||
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
||||
return;
|
||||
}
|
||||
|
||||
if (@available(iOS 10, *)) {
|
||||
if ([@"HapticFeedbackType.lightImpact" isEqualToString: feedbackType]) {
|
||||
[[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight] impactOccurred];
|
||||
} else if ([@"HapticFeedbackType.mediumImpact" isEqualToString: feedbackType]) {
|
||||
[[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium] impactOccurred];
|
||||
} else if ([@"HapticFeedbackType.heavyImpact" isEqualToString: feedbackType]) {
|
||||
[[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy] impactOccurred];
|
||||
} else if ([@"HapticFeedbackType.selectionClick" isEqualToString: feedbackType]) {
|
||||
[[[UISelectionFeedbackGenerator alloc] init] selectionChanged];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setSystemChromePreferredOrientations:(NSArray*)orientations {
|
||||
|
||||
Reference in New Issue
Block a user