summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ios.h1
-rw-r--r--src/ios.m43
-rw-r--r--src/ui/documentwidget.c3
3 files changed, 36 insertions, 11 deletions
diff --git a/src/ios.h b/src/ios.h
index a8039c1c..70b889bf 100644
--- a/src/ios.h
+++ b/src/ios.h
@@ -28,6 +28,7 @@ iDeclareType(Window)
28 28
29enum iHapticEffect { 29enum iHapticEffect {
30 tap_HapticEffect, 30 tap_HapticEffect,
31 gentleTap_HapticEffect,
31}; 32};
32 33
33void setupApplication_iOS (void); 34void setupApplication_iOS (void);
diff --git a/src/ios.m b/src/ios.m
index 82a8c0c8..b82d54a7 100644
--- a/src/ios.m
+++ b/src/ios.m
@@ -66,6 +66,7 @@ API_AVAILABLE(ios(13.0))
66@interface HapticState : NSObject 66@interface HapticState : NSObject
67@property (nonatomic, strong) CHHapticEngine *engine; 67@property (nonatomic, strong) CHHapticEngine *engine;
68@property (nonatomic, strong) NSDictionary *tapDef; 68@property (nonatomic, strong) NSDictionary *tapDef;
69@property (nonatomic, strong) NSDictionary *gentleTapDef;
69@end 70@end
70 71
71@implementation HapticState 72@implementation HapticState
@@ -107,26 +108,47 @@ API_AVAILABLE(ios(13.0))
107 CHHapticPatternKeyEvent: @{ 108 CHHapticPatternKeyEvent: @{
108 CHHapticPatternKeyEventType: CHHapticEventTypeHapticTransient, 109 CHHapticPatternKeyEventType: CHHapticEventTypeHapticTransient,
109 CHHapticPatternKeyTime: @0.0, 110 CHHapticPatternKeyTime: @0.0,
110 CHHapticPatternKeyEventDuration:@0.1 111 CHHapticPatternKeyEventDuration:@0.1,
112 CHHapticPatternKeyEventParameters: @[
113 @{
114 CHHapticPatternKeyParameterID: CHHapticEventParameterIDHapticIntensity,
115 CHHapticPatternKeyParameterValue: @1.0
116 }
117 ]
111 }, 118 },
112 }, 119 },
113 ], 120 ]
121 };
122 self.gentleTapDef = @{
123 CHHapticPatternKeyPattern:
124 @[
125 @{
126 CHHapticPatternKeyEvent: @{
127 CHHapticPatternKeyEventType: CHHapticEventTypeHapticTransient,
128 CHHapticPatternKeyTime: @0.0,
129 CHHapticPatternKeyEventDuration:@0.1,
130 CHHapticPatternKeyEventParameters: @[
131 @{
132 CHHapticPatternKeyParameterID: CHHapticEventParameterIDHapticIntensity,
133 CHHapticPatternKeyParameterValue: @0.33
134 }
135 ]
136 },
137 },
138 ]
114 }; 139 };
115} 140}
116 141
117-(void)playTapEffect { 142
143-(void)playHapticEffect:(NSDictionary *)def {
118 NSError *error = nil; 144 NSError *error = nil;
119 CHHapticPattern *pattern = [[CHHapticPattern alloc] initWithDictionary:self.tapDef 145 CHHapticPattern *pattern = [[CHHapticPattern alloc] initWithDictionary:def
120 error:&error]; 146 error:&error];
121 // TODO: Check the error. 147 // TODO: Check the error.
122 id<CHHapticPatternPlayer> player = [self.engine createPlayerWithPattern:pattern error:&error]; 148 id<CHHapticPatternPlayer> player = [self.engine createPlayerWithPattern:pattern error:&error];
123 // TODO: Check the error. 149 // TODO: Check the error.
124 [self.engine startWithCompletionHandler:^(NSError *err){ 150 [self.engine startWithCompletionHandler:^(NSError *err){
125 if (err == nil) { 151 if (err == nil) {
126 /* Just keep it running. */
127// [self.engine notifyWhenPlayersFinished:^(NSError * _Nullable error) {
128// return CHHapticEngineFinishedActionStopEngine;
129// }];
130 NSError *startError = nil; 152 NSError *startError = nil;
131 [player startAtTime:0.0 error:&startError]; 153 [player startAtTime:0.0 error:&startError];
132 } 154 }
@@ -341,7 +363,10 @@ void playHapticEffect_iOS(enum iHapticEffect effect) {
341 HapticState *hs = (HapticState *) appState_.haptic; 363 HapticState *hs = (HapticState *) appState_.haptic;
342 switch(effect) { 364 switch(effect) {
343 case tap_HapticEffect: 365 case tap_HapticEffect:
344 [hs playTapEffect]; 366 [hs playHapticEffect:hs.tapDef];
367 break;
368 case gentleTap_HapticEffect:
369 [hs playHapticEffect:hs.gentleTapDef];
345 break; 370 break;
346 } 371 }
347 } 372 }
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index bd624059..0fe8220e 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -2842,8 +2842,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
2842 postCommand_App("sidebar.toggle"); 2842 postCommand_App("sidebar.toggle");
2843 showToolbar_Root(get_Root(), iTrue); 2843 showToolbar_Root(get_Root(), iTrue);
2844#if defined (iPlatformAppleMobile) 2844#if defined (iPlatformAppleMobile)
2845 /* TODO: Add a softer tap? */ 2845 playHapticEffect_iOS(gentleTap_HapticEffect);
2846// playHapticEffect_iOS(tap_HapticEffect);
2847#endif 2846#endif
2848 return iTrue; 2847 return iTrue;
2849 } 2848 }