Skip to content

Commit

Permalink
fix: memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Le Hau authored and Le Hau committed Jun 2, 2022
1 parent 366e689 commit d2f63e4
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 4 deletions.
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ PODS:
- React-jsi (= 0.68.2)
- React-logger (= 0.68.2)
- React-perflogger (= 0.68.2)
- RNCardScanner (1.0.5):
- RNCardScanner (1.0.7):
- React-Core
- RNScreens (3.13.1):
- React-Core
Expand Down Expand Up @@ -556,7 +556,7 @@ SPEC CHECKSUMS:
React-RCTVibration: 79040b92bfa9c3c2d2cb4f57e981164ec7ab9374
React-runtimeexecutor: b960b687d2dfef0d3761fbb187e01812ebab8b23
ReactCommon: 095366164a276d91ea704ce53cb03825c487a3f2
RNCardScanner: ede91abf432c6cb7cc33df6d7f99092bdd6dd14c
RNCardScanner: b1c393b9730d0bbe057ac6a3fdb427f505fb3d9f
RNScreens: 40a2cb40a02a609938137a1e0acfbf8fc9eebf19
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
Yoga: 99652481fcd320aefa4a7ef90095b95acd181952
Expand Down
4 changes: 4 additions & 0 deletions ios/CardScanner/CardScannerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@

- (void)resetResult;

- (void)startCamera;

- (void)stopCamera;

@end

17 changes: 17 additions & 0 deletions ios/CardScanner/CardScannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ - (void)resetResult {
[_recognizer resetResult];
}

- (void)startCamera {
[_recognizer startCamera];
}

- (void)stopCamera {
[_recognizer stopCamera];
}

- (void)didMoveToWindow
{
[super didMoveToWindow];
BOOL isVisible = self.superview && self.window;
if (!isVisible) {
[_recognizer stopCamera];
}
}

#pragma mark PayCardsRecognizerPlatformDelegate

- (void)payCardsRecognizer:(PayCardsRecognizer * _Nonnull)payCardsRecognizer didRecognize:(PayCardsRecognizerResult * _Nonnull)result {
Expand Down
16 changes: 16 additions & 0 deletions ios/CardScanner/CardScannerViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ - (UIView *)view
}];
}

RCT_EXPORT_METHOD(startCamera: (nonnull NSNumber *)viewTag)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, CardScannerView *> *viewRegistry) {
CardScannerView *view = viewRegistry[viewTag];
[view startCamera];
}];
}

RCT_EXPORT_METHOD(stopCamera: (nonnull NSNumber *)viewTag)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, CardScannerView *> *viewRegistry) {
CardScannerView *view = viewRegistry[viewTag];
[view stopCamera];
}];
}

RCT_EXPORT_VIEW_PROPERTY(frameColor, UIColor);

RCT_EXPORT_VIEW_PROPERTY(onDidScanCard, RCTBubblingEventBlock)
Expand Down
3 changes: 2 additions & 1 deletion ios/CardScanner/PayCardsRecognizer.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
<array>
<dict>
<key>LibraryIdentifier</key>
<string>ios-i386_x86_64-simulator</string>
<string>ios-arm64_i386_x86_64-simulator</string>
<key>LibraryPath</key>
<string>PayCardsRecognizer.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>i386</string>
<string>x86_64</string>
</array>
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rn-card-scanner",
"version": "1.0.6",
"version": "1.0.7",
"description": "Credit card scanner for React Native",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
8 changes: 8 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const CardScanner: React.ForwardRefRenderFunction<

const toggleFlashId = getCommandId(Commands.toggleFlash);
const resetResultId = getCommandId(Commands.resetResult);
const startCameraId = getCommandId(Commands.startCamera);
const stopCameraId = getCommandId(Commands.stopCamera);

return {
toggleFlash() {
Expand All @@ -86,6 +88,12 @@ const CardScanner: React.ForwardRefRenderFunction<
resetResult() {
UIManager.dispatchViewManagerCommand(viewId, resetResultId, []);
},
startCamera() {
UIManager.dispatchViewManagerCommand(viewId, startCameraId, []);
},
stopCamera() {
UIManager.dispatchViewManagerCommand(viewId, stopCameraId, []);
},
};
},
[]
Expand Down

0 comments on commit d2f63e4

Please sign in to comment.