Skip to content

Commit bd5bfea

Browse files
author
Jack Sobocinski
committed
add roatation gesutre handler
1 parent 80446f2 commit bd5bfea

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

ARKit.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class ARKit extends Component {
5858
keyBy([
5959
'onTapOnPlaneUsingExtent',
6060
'onTapOnPlaneNoExtent',
61+
'onRotationGesture',
6162
'onPlaneDetected',
6263
'onPlaneRemoved',
6364
'onPlaneUpdated',
@@ -238,6 +239,7 @@ ARKit.propTypes = {
238239
onTrackingState: PropTypes.func,
239240
onTapOnPlaneUsingExtent: PropTypes.func,
240241
onTapOnPlaneNoExtent: PropTypes.func,
242+
onRotationGesture: PropTypes.func,
241243
onEvent: PropTypes.func,
242244
isMounted: PropTypes.func,
243245
isInitialized: PropTypes.func,

ios/RCTARKit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef void (^RCTARKitReject)(NSString *code, NSString *message, NSError *error
5050
@property (nonatomic, copy) RCTBubblingEventBlock onPlaneRemoved;
5151
@property (nonatomic, copy) RCTBubblingEventBlock onPlaneUpdated;
5252

53+
5354
@property (nonatomic, copy) RCTBubblingEventBlock onAnchorDetected;
5455
@property (nonatomic, copy) RCTBubblingEventBlock onAnchorRemoved;
5556
@property (nonatomic, copy) RCTBubblingEventBlock onAnchorUpdated;
@@ -61,6 +62,9 @@ typedef void (^RCTARKitReject)(NSString *code, NSString *message, NSError *error
6162
@property (nonatomic, copy) RCTBubblingEventBlock onTrackingState;
6263
@property (nonatomic, copy) RCTBubblingEventBlock onTapOnPlaneUsingExtent;
6364
@property (nonatomic, copy) RCTBubblingEventBlock onTapOnPlaneNoExtent;
65+
66+
@property (nonatomic, copy) RCTBubblingEventBlock onRotationGesture;
67+
6468
@property (nonatomic, copy) RCTBubblingEventBlock onEvent;
6569
@property (nonatomic, copy) RCTBubblingEventBlock onARKitError;
6670

ios/RCTARKit.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ - (instancetype)initWithARView:(ARSCNView *)arView {
7676
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
7777
tapGestureRecognizer.numberOfTapsRequired = 1;
7878
[self.arView addGestureRecognizer:tapGestureRecognizer];
79+
80+
UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotationFrom:)];
81+
[self.arView addGestureRecognizer:rotationGestureRecognizer];
7982

8083
self.touchDelegates = [NSMutableArray array];
8184
self.rendererDelegates = [NSMutableArray array];
@@ -550,7 +553,22 @@ - (void)handleTapFrom: (UITapGestureRecognizer *)recognizer {
550553
}
551554
}
552555

556+
- (void)handleRotationFrom: (UIRotationGestureRecognizer *)recognizer {
557+
558+
if( recognizer.state == UIGestureRecognizerStateBegan ||
559+
recognizer.state == UIGestureRecognizerStateChanged ||
560+
recognizer.state == UIGestureRecognizerStateEnded) {
561+
562+
if(self.onRotationGesture) {
563+
NSDictionary *rotationGesture = @{
564+
@"rotation": @(recognizer.rotation),
565+
@"velocity": @(recognizer.velocity)
566+
};
553567

568+
self.onRotationGesture(rotationGesture);
569+
}
570+
}
571+
}
554572

555573
#pragma mark - ARSCNViewDelegate
556574

ios/RCTARKitManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ - (NSDictionary *)constantsToExport
188188
RCT_EXPORT_VIEW_PROPERTY(onLightEstimation, RCTBubblingEventBlock)
189189
RCT_EXPORT_VIEW_PROPERTY(onTapOnPlaneUsingExtent, RCTBubblingEventBlock)
190190
RCT_EXPORT_VIEW_PROPERTY(onTapOnPlaneNoExtent, RCTBubblingEventBlock)
191+
RCT_EXPORT_VIEW_PROPERTY(onRotationGesture, RCTBubblingEventBlock)
191192
RCT_EXPORT_VIEW_PROPERTY(onEvent, RCTBubblingEventBlock)
192193
RCT_EXPORT_VIEW_PROPERTY(onARKitError, RCTBubblingEventBlock)
193194
RCT_EXPORT_VIEW_PROPERTY(worldMap, NSObject);

0 commit comments

Comments
 (0)