@@ -13,26 +13,29 @@ + (BOOL)requiresMainQueueSetup
1313- (instancetype )init
1414{
1515 self = [super init ];
16+
1617 if (self) {
17- _notificationGenerator = [UINotificationFeedbackGenerator new ];
18- [_notificationGenerator prepare ];
19-
20- _selectionGenerator = [UISelectionFeedbackGenerator new ];
21- [_selectionGenerator prepare ];
22-
23- _impactStyles = @{
24- @" light" : @(UIImpactFeedbackStyleLight),
25- @" medium" : @(UIImpactFeedbackStyleMedium),
26- @" heavy" : @(UIImpactFeedbackStyleHeavy),
27- @" soft" : @(UIImpactFeedbackStyleSoft),
28- @" rigid" : @(UIImpactFeedbackStyleRigid)
29- };
30-
31- _notificationTypes = @{
32- @" success" : @(UINotificationFeedbackTypeSuccess),
33- @" warning" : @(UINotificationFeedbackTypeWarning),
34- @" error" : @(UINotificationFeedbackTypeError)
35- };
18+ _notificationGenerator = [UINotificationFeedbackGenerator new ];
19+ [_notificationGenerator prepare ];
20+
21+ _selectionGenerator = [UISelectionFeedbackGenerator new ];
22+ [_selectionGenerator prepare ];
23+
24+ _impactGenerators = [NSMutableDictionary new ];
25+
26+ _impactStyles = @{
27+ @" light" : @(UIImpactFeedbackStyleLight),
28+ @" medium" : @(UIImpactFeedbackStyleMedium),
29+ @" heavy" : @(UIImpactFeedbackStyleHeavy),
30+ @" soft" : @(UIImpactFeedbackStyleSoft),
31+ @" rigid" : @(UIImpactFeedbackStyleRigid)
32+ };
33+
34+ _notificationTypes = @{
35+ @" success" : @(UINotificationFeedbackTypeSuccess),
36+ @" warning" : @(UINotificationFeedbackTypeWarning),
37+ @" error" : @(UINotificationFeedbackTypeError)
38+ };
3639 }
3740 return self;
3841}
@@ -47,11 +50,15 @@ - (void)impact:(NSString *)style
4750 reject (@" E_INVALID_STYLE" , [NSString stringWithFormat: @" Invalid impact style '%@ '" , style], nil );
4851 return ;
4952 }
50- UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc ]
51- initWithStyle: (UIImpactFeedbackStyle)styleValue.integerValue];
52- [generator prepare ];
53- [generator impactOccurred ];
53+ UIImpactFeedbackGenerator *generator = self.impactGenerators [style];
5454
55+ if (!generator) {
56+ generator = [[UIImpactFeedbackGenerator alloc ]
57+ initWithStyle: (UIImpactFeedbackStyle)styleValue.integerValue];
58+ [generator prepare ];
59+ self.impactGenerators [style] = generator;
60+ }
61+ [generator impactOccurred ];
5562 resolve (nil );
5663}
5764
@@ -71,7 +78,6 @@ - (void)notification:(NSString *)type
7178
7279- (void )selection : (nonnull RCTPromiseResolveBlock)resolve
7380 reject : (nonnull RCTPromiseRejectBlock)reject {
74- [self .selectionGenerator prepare ];
7581 [self .selectionGenerator selectionChanged ];
7682 resolve (nil );
7783}
0 commit comments