Skip to content

Commit fd90bd5

Browse files
feat: add custom app rating api (#1186)
* map: custom app rating api * chore: revert non-related committed files * chore: apply lint fix * fix: remove useless comments * chore: rename willRedirectToAppStore to willRedirectToStore, chore: add the changes to CHANGELOG.md * chore: add the changes to CHANGELOG.md * update: test function name to follow the new naming conversions, update: function (willRedirectToStore)implementation to be able to support older versions * Update CHANGELOG.md Co-authored-by: Ahmed Mahmoud <[email protected]> --------- Co-authored-by: Ahmed Mahmoud <[email protected]>
1 parent 70e349c commit fd90bd5

File tree

10 files changed

+62
-0
lines changed

10 files changed

+62
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v12.9.0...dev)
4+
5+
### Added
6+
7+
- Add `Instabug.willRedirectToStore` API for use in custom app rating prompts ([#1186](https://github.com/Instabug/Instabug-React-Native/pull/1186)).
8+
39
## [12.9.0](https://github.com/Instabug/Instabug-React-Native/compare/v12.8.0...dev)(April 2, 2024)
410

511
### Added

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,20 @@ public void run() {
10561056
});
10571057
}
10581058

1059+
@ReactMethod
1060+
public void willRedirectToStore() {
1061+
MainThreadHandler.runOnMainThread(new Runnable() {
1062+
@Override
1063+
public void run() {
1064+
try {
1065+
Instabug.willRedirectToStore();
1066+
} catch (Exception e) {
1067+
e.printStackTrace();
1068+
}
1069+
}
1070+
});
1071+
}
1072+
10591073
/**
10601074
* Map between the exported JS constant and the arg key in {@link ArgsRegistry}.
10611075
* The constant name and the arg key should match to be able to resolve the

android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,4 +576,13 @@ public void testIdentifyUserWithId() {
576576
verify(Instabug.class,times(1));
577577
Instabug.clearAllExperiments();
578578
}
579+
580+
@Test
581+
public void testWillRedirectToStore() {
582+
// when
583+
rnModule.willRedirectToStore();
584+
585+
// then
586+
mockInstabug.verify(() -> Instabug.willRedirectToStore());
587+
}
579588
}

examples/default/ios/InstabugTests/InstabugSampleTests.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,19 @@ - (void)testShow {
340340
}
341341

342342

343+
- (void)testWillRedirectToStore {
344+
345+
id mock = OCMClassMock([Instabug class]);
346+
347+
[self.instabugBridge willRedirectToStore];
348+
349+
OCMVerify([mock willRedirectToAppStore]);
350+
351+
[mock stopMocking];
352+
}
353+
354+
355+
343356
/*
344357
+------------------------------------------------------------------------+
345358
| Log Module |

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282

8383
- (void)show;
8484

85+
- (void) willRedirectToStore;
86+
8587

8688
/*
8789
+------------------------------------------------------------------------+

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ - (dispatch_queue_t)methodQueue {
382382
[Instabug clearAllExperiments];
383383
}
384384

385+
RCT_EXPORT_METHOD(willRedirectToStore){
386+
[Instabug willRedirectToAppStore];
387+
}
388+
385389
- (NSDictionary *)constantsToExport {
386390
return ArgsRegistry.getAll;
387391
}

src/modules/Instabug.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,13 @@ export const clearAllExperiments = () => {
559559
NativeInstabug.clearAllExperiments();
560560
};
561561

562+
/**
563+
* This API has to be call when using custom app rating prompt
564+
*/
565+
export const willRedirectToStore = () => {
566+
NativeInstabug.willRedirectToStore();
567+
};
568+
562569
export const componentDidAppearListener = (event: ComponentDidAppearEvent) => {
563570
if (_isFirstScreen) {
564571
_lastScreen = event.componentName;

src/native/NativeInstabug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export interface InstabugNativeModule extends NativeModule {
105105
logInfoToReport(log: string): void;
106106
addFileAttachmentWithURLToReport(url: string, filename?: string): void;
107107
addFileAttachmentWithDataToReport(data: string, filename?: string): void;
108+
willRedirectToStore(): void;
108109
}
109110

110111
export const NativeInstabug = NativeModules.Instabug;

test/mocks/mockInstabug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const mockInstabug: InstabugNativeModule = {
6464
addFileAttachmentWithURLToReport: jest.fn(),
6565
addFileAttachmentWithDataToReport: jest.fn(),
6666
setNetworkLoggingEnabled: jest.fn(),
67+
willRedirectToStore: jest.fn(),
6768
};
6869

6970
export default mockInstabug;

test/modules/Instabug.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,4 +769,9 @@ describe('Instabug Module', () => {
769769
Instabug.clearAllExperiments();
770770
expect(NativeInstabug.clearAllExperiments).toBeCalledTimes(1);
771771
});
772+
773+
it('should call the native willRedirectToStore method', () => {
774+
Instabug.willRedirectToStore();
775+
expect(NativeInstabug.willRedirectToStore).toBeCalledTimes(1);
776+
});
772777
});

0 commit comments

Comments
 (0)