react-native-rate-app 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +130 -0
- package/android/build.gradle +91 -0
- package/android/generated/java/com/rateapp/NativeRateAppSpec.java +38 -0
- package/android/generated/jni/CMakeLists.txt +49 -0
- package/android/generated/jni/RNRateAppSpec-generated.cpp +32 -0
- package/android/generated/jni/RNRateAppSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNRateAppSpec/ComponentDescriptors.cpp +22 -0
- package/android/generated/jni/react/renderer/components/RNRateAppSpec/ComponentDescriptors.h +24 -0
- package/android/generated/jni/react/renderer/components/RNRateAppSpec/EventEmitters.cpp +16 -0
- package/android/generated/jni/react/renderer/components/RNRateAppSpec/EventEmitters.h +17 -0
- package/android/generated/jni/react/renderer/components/RNRateAppSpec/Props.cpp +19 -0
- package/android/generated/jni/react/renderer/components/RNRateAppSpec/Props.h +18 -0
- package/android/generated/jni/react/renderer/components/RNRateAppSpec/RNRateAppSpecJSI-generated.cpp +26 -0
- package/android/generated/jni/react/renderer/components/RNRateAppSpec/RNRateAppSpecJSI.h +67 -0
- package/android/generated/jni/react/renderer/components/RNRateAppSpec/ShadowNodes.cpp +17 -0
- package/android/generated/jni/react/renderer/components/RNRateAppSpec/ShadowNodes.h +23 -0
- package/android/generated/jni/react/renderer/components/RNRateAppSpec/States.cpp +16 -0
- package/android/generated/jni/react/renderer/components/RNRateAppSpec/States.h +19 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/rateapp/RateAppModule.kt +46 -0
- package/android/src/main/java/com/rateapp/RateAppPackage.kt +34 -0
- package/android/src/newarch/RateAppSpec.kt +7 -0
- package/android/src/oldarch/RateAppSpec.kt +11 -0
- package/ios/RateApp.h +12 -0
- package/ios/RateApp.mm +39 -0
- package/ios/generated/RNRateAppSpec/ComponentDescriptors.cpp +22 -0
- package/ios/generated/RNRateAppSpec/ComponentDescriptors.h +24 -0
- package/ios/generated/RNRateAppSpec/EventEmitters.cpp +16 -0
- package/ios/generated/RNRateAppSpec/EventEmitters.h +17 -0
- package/ios/generated/RNRateAppSpec/Props.cpp +19 -0
- package/ios/generated/RNRateAppSpec/Props.h +18 -0
- package/ios/generated/RNRateAppSpec/RCTComponentViewHelpers.h +18 -0
- package/ios/generated/RNRateAppSpec/RNRateAppSpec-generated.mm +29 -0
- package/ios/generated/RNRateAppSpec/RNRateAppSpec.h +50 -0
- package/ios/generated/RNRateAppSpec/ShadowNodes.cpp +17 -0
- package/ios/generated/RNRateAppSpec/ShadowNodes.h +23 -0
- package/ios/generated/RNRateAppSpec/States.cpp +16 -0
- package/ios/generated/RNRateAppSpec/States.h +19 -0
- package/ios/generated/RNRateAppSpecJSI-generated.cpp +26 -0
- package/ios/generated/RNRateAppSpecJSI.h +67 -0
- package/lib/commonjs/NativeRateApp.js +9 -0
- package/lib/commonjs/NativeRateApp.js.map +1 -0
- package/lib/commonjs/constants.js +15 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/index.js +120 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/types.js +14 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/NativeRateApp.js +5 -0
- package/lib/module/NativeRateApp.js.map +1 -0
- package/lib/module/constants.js +11 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/index.js +88 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/types.js +10 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/setupJest.d.ts +1 -0
- package/lib/typescript/commonjs/setupJest.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/NativeRateApp.d.ts +7 -0
- package/lib/typescript/commonjs/src/NativeRateApp.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/constants.d.ts +4 -0
- package/lib/typescript/commonjs/src/constants.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +26 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types.d.ts +22 -0
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/setupJest.d.ts +1 -0
- package/lib/typescript/module/setupJest.d.ts.map +1 -0
- package/lib/typescript/module/src/NativeRateApp.d.ts +7 -0
- package/lib/typescript/module/src/NativeRateApp.d.ts.map +1 -0
- package/lib/typescript/module/src/constants.d.ts +4 -0
- package/lib/typescript/module/src/constants.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +26 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/types.d.ts +22 -0
- package/lib/typescript/module/src/types.d.ts.map +1 -0
- package/package.json +156 -0
- package/react-native-rate-app.podspec +23 -0
- package/src/NativeRateApp.ts +8 -0
- package/src/constants.ts +10 -0
- package/src/index.tsx +91 -0
- package/src/types.ts +22 -0
package/src/constants.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AndroidMarket } from "./types";
|
|
2
|
+
|
|
3
|
+
export const IOS_REVIEW_URL = "itms-apps://apps.apple.com/app/id";
|
|
4
|
+
|
|
5
|
+
export const ANDROID_MARKET_URLS: Record<AndroidMarket, string> = {
|
|
6
|
+
[AndroidMarket.GOOGLE]: "market://details?id={packageName}",
|
|
7
|
+
[AndroidMarket.AMAZON]: "amzn://apps/android?p={packageName}",
|
|
8
|
+
[AndroidMarket.SAMSUNG]: "samsungapps://ProductDetail/{packageName}",
|
|
9
|
+
[AndroidMarket.HUAWEI]: "appmarket://details?id={packageName}",
|
|
10
|
+
};
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Linking, Platform } from "react-native";
|
|
2
|
+
import NativeRateApp from "./NativeRateApp";
|
|
3
|
+
import { ANDROID_MARKET_URLS, IOS_REVIEW_URL } from "./constants";
|
|
4
|
+
import { AndroidMarket, type OpenStoreForReviewProps } from "./types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Custom error for rate app operations
|
|
8
|
+
*/
|
|
9
|
+
class RateAppError extends Error {
|
|
10
|
+
constructor(message: string) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "RateAppError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const RateApp = {
|
|
17
|
+
/**
|
|
18
|
+
* Requests a review from the user.
|
|
19
|
+
* @returns A promise that resolves to a boolean indicating whether the review was successfully requested.
|
|
20
|
+
*/
|
|
21
|
+
async requestReview(): Promise<boolean> {
|
|
22
|
+
try {
|
|
23
|
+
return await NativeRateApp.requestReview();
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw new RateAppError(`Failed to request review: ${error}`);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Opens the store listing for the app.
|
|
31
|
+
* @param props The properties for the store listing.
|
|
32
|
+
* @returns A promise that resolves to a boolean indicating whether the store listing was successfully opened.
|
|
33
|
+
*/
|
|
34
|
+
async openStoreForReview({
|
|
35
|
+
iOSAppId,
|
|
36
|
+
androidPackageName,
|
|
37
|
+
androidMarket = AndroidMarket.GOOGLE,
|
|
38
|
+
}: OpenStoreForReviewProps): Promise<boolean> {
|
|
39
|
+
const isIOS = Platform.OS === "ios";
|
|
40
|
+
const ismacOS = Platform.OS === "macos";
|
|
41
|
+
const isAndroid = Platform.OS === "android";
|
|
42
|
+
let url = "";
|
|
43
|
+
|
|
44
|
+
if (isIOS || ismacOS) {
|
|
45
|
+
if (!iOSAppId) {
|
|
46
|
+
throw new RateAppError("iOSAppId is required for iOS and macOS");
|
|
47
|
+
}
|
|
48
|
+
url = `${IOS_REVIEW_URL}${iOSAppId}?action=write-review`;
|
|
49
|
+
} else if (isAndroid) {
|
|
50
|
+
if (!androidPackageName) {
|
|
51
|
+
throw new RateAppError("androidPackageName is required for Android");
|
|
52
|
+
}
|
|
53
|
+
url = this.getAndroidMarketUrl(androidMarket, androidPackageName);
|
|
54
|
+
} else {
|
|
55
|
+
throw new RateAppError(`Unsupported platform: ${Platform.OS}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const canOpenURL = await Linking.canOpenURL(url);
|
|
60
|
+
if (canOpenURL) {
|
|
61
|
+
await Linking.openURL(url);
|
|
62
|
+
}
|
|
63
|
+
return canOpenURL;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
throw new RateAppError(`Failed to open store for review: ${error}`);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Gets the URL for the Android market.
|
|
71
|
+
* @param androidMarket The market where the app's store listing should be opened on Android.
|
|
72
|
+
* @param androidPackageName The package name of the app to open the store listing for on Android.
|
|
73
|
+
* @returns The URL for the Android market.
|
|
74
|
+
*/
|
|
75
|
+
getAndroidMarketUrl(
|
|
76
|
+
androidMarket: AndroidMarket,
|
|
77
|
+
androidPackageName: string,
|
|
78
|
+
): string {
|
|
79
|
+
const urlTemplate = ANDROID_MARKET_URLS[androidMarket];
|
|
80
|
+
if (!urlTemplate) {
|
|
81
|
+
throw new RateAppError(`Unsupported Android market: ${androidMarket}`);
|
|
82
|
+
}
|
|
83
|
+
return urlTemplate.replace("{packageName}", androidPackageName);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export * from "./types";
|
|
88
|
+
export * from "./constants";
|
|
89
|
+
export const { requestReview, openStoreForReview, getAndroidMarketUrl } =
|
|
90
|
+
RateApp;
|
|
91
|
+
export default RateApp;
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export enum AndroidMarket {
|
|
2
|
+
GOOGLE = "google",
|
|
3
|
+
AMAZON = "amazon",
|
|
4
|
+
SAMSUNG = "samsung",
|
|
5
|
+
HUAWEI = "huawei",
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface OpenStoreForReviewProps {
|
|
9
|
+
/**
|
|
10
|
+
* The App Store ID of the app to open the store listing for on iOS.
|
|
11
|
+
*/
|
|
12
|
+
iOSAppId?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The package name of the app to open the store listing for on Android.
|
|
15
|
+
*/
|
|
16
|
+
androidPackageName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The market where the app's store listing should be opened on Android.
|
|
19
|
+
* @default AndroidMarket.GOOGLE
|
|
20
|
+
*/
|
|
21
|
+
androidMarket?: AndroidMarket;
|
|
22
|
+
}
|