Skip to content

Commit 076ef26

Browse files
committed
Merge branch 'main' of github.com:3dsinteractive/pam-react-native
2 parents 74b4036 + e489404 commit 076ef26

File tree

8 files changed

+69
-54
lines changed

8 files changed

+69
-54
lines changed

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git/
2+
node_modules/
3+
src/
4+
*.log

example/src/App.tsx

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Pam } from 'pam-react-native';
22
import { Button, Text, View, StyleSheet } from 'react-native';
3-
import { useEffect } from 'react';
3+
import { useEffect, useState } from 'react';
44

55
export default function App() {
6+
const [contactID, setContactID] = useState<string | undefined>('');
7+
68
useEffect(() => {
79
Pam.initialize({
8-
baseApi: 'https://stgx.pams.ai',
10+
baseApi: 'https://awc-uat.pams.ai',
911
trackingConsentMessageId: '2VNmHzWrxPYJj0zDiM1cQGeW2S5',
1012
publicDBAlias: 'ecom-public',
1113
loginDBAlias: 'ecom-login',
@@ -26,25 +28,46 @@ export default function App() {
2628
});
2729
}
2830

29-
function allowConsent() {
30-
Pam.allowAllTrackingConsent('2VNmHzWrxPYJj0zDiM1cQGeW2S5');
31+
function sendEvent() {
32+
Pam.track('click-btn', {});
33+
}
34+
35+
async function allowConsent() {
36+
await Pam.allowAllTrackingConsent('2VNmHzWrxPYJj0zDiM1cQGeW2S5');
37+
38+
const cid = Pam.shared?.contactState?.getContactId();
39+
setContactID(cid);
3140
}
3241

3342
return (
3443
<View style={styles.container}>
35-
<Text>Test</Text>
36-
<Button
37-
onPress={allowConsent}
38-
title="allowConsent"
39-
color="#841584"
40-
accessibilityLabel="Learn more about this purple button"
41-
/>
42-
<Button
43-
onPress={onPressLearnMore}
44-
title="load App Attention"
45-
color="#841584"
46-
accessibilityLabel="Learn more about this purple button"
47-
/>
44+
<Text style={styles.mb}>Contact ID: {contactID}</Text>
45+
<View style={styles.mb}>
46+
<Button
47+
onPress={allowConsent}
48+
title="allowConsent"
49+
color="#ff3300"
50+
accessibilityLabel="Learn more about this purple button"
51+
/>
52+
</View>
53+
54+
<View style={styles.mb}>
55+
<Button
56+
onPress={sendEvent}
57+
title="Send Event"
58+
color="#669933"
59+
accessibilityLabel="Learn more about this purple button"
60+
/>
61+
</View>
62+
63+
<View style={styles.mb}>
64+
<Button
65+
onPress={onPressLearnMore}
66+
title="load App Attention"
67+
color="#ff0066"
68+
accessibilityLabel="Learn more about this purple button"
69+
/>
70+
</View>
4871
</View>
4972
);
5073
}
@@ -55,4 +78,7 @@ const styles = StyleSheet.create({
5578
alignItems: 'center',
5679
justifyContent: 'center',
5780
},
81+
mb: {
82+
marginBottom: 10,
83+
},
5884
});

ios/PamReactNative.swift

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,27 @@ import UIKit
33
@objc(PamReactNative)
44
class PamReactNative: NSObject {
55

6-
@objc(multiply:withB:withResolver:withRejecter:)
7-
func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
8-
resolve(a*b)
9-
}
10-
11-
12-
136
@objc(displayPopup:withBtnColor:withBtnLabel:withBtnLabelColor:withResolver:withRejecter:)
14-
func displayPopup(banner:NSDictionary, btnColor: String, btnLabel:String, btnLabelColor: String, resolve: @escaping RCTPromiseResolveBlock,reject: @escaping RCTPromiseRejectBlock) -> Void {
7+
func displayPopup(
8+
banner: NSDictionary, btnColor: String, btnLabel: String, btnLabelColor: String,
9+
resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
10+
) {
1511
DispatchQueue.main.async {
1612
let popupVC = PopupViewController()
1713
popupVC.resolve = resolve
18-
popupVC.popupData = banner as? [String:Any]
14+
popupVC.popupData = banner as? [String: Any]
1915
popupVC.modalPresentationStyle = .overFullScreen // ให้แสดงแบบเต็มจอ
20-
16+
2117
popupVC.btnColor = btnColor
2218
popupVC.btnLabel = btnLabel
2319
popupVC.btnLabelColor = btnLabelColor
24-
20+
2521
if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
26-
let window = scene.windows.first {
27-
window.rootViewController?.present(popupVC, animated: false, completion: nil)
22+
let window = scene.windows.first
23+
{
24+
window.rootViewController?.present(popupVC, animated: false, completion: nil)
2825
}
29-
26+
3027
}
3128
}
3229

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "pam-react-native",
3-
"version": "0.1.0",
3+
"version": "0.1.11",
44
"description": "Pam SDK for React Native",
55
"source": "./src/index.tsx",
66
"main": "./lib/commonjs/index.js",
77
"module": "./lib/module/index.js",
8+
"types": "./lib/typescript/module/src/index.d.ts",
89
"exports": {
910
".": {
1011
"import": {

publish.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
yarn
2+
yarn prepare
3+
npm publish --access public

src/PamTracker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class PamTracker {
109109
});
110110

111111
constructor(config: IConfig, storage?: IStorageProvider) {
112-
Utils.setConfig(config);
112+
// Utils.setConfig(config);
113113
if (storage) {
114114
this.storage = storage;
115115
Utils.setStorageProvider(storage);

src/index.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ const PamReactNative = NativeModules.PamReactNative
3434
}
3535
);
3636

37-
export function multiply(a: number, b: number): Promise<number> {
38-
return PamReactNative.multiply(a, b);
39-
}
40-
4137
interface PamConfig {
4238
baseApi: string;
4339
trackingConsentMessageId: string;
@@ -96,18 +92,6 @@ export class Pam {
9692
| ((banner: any) => boolean)
9793
| ((banner: any) => Promise<boolean>)
9894
) {
99-
// console.log('appAttention', pageName);
100-
101-
// const banner = {
102-
// title: 'title',
103-
// description: 'description',
104-
// image:
105-
// 'https://s3-ap-southeast-1.amazonaws.com/pam4-sansiri/ecom/public/2sFQrLjdyBbXkHkAMV03HrNtbhC.jpg',
106-
// size: 'large',
107-
// };
108-
109-
// PamReactNative.displayPopup(banner, btnColor, btnLabel, btnLabelColor);
110-
11195
const contectID = Pam._instance.contactState?.getContactId();
11296
if (contectID) {
11397
const appAttention = await Pam.pamApi.loadAppAttention(

src/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import type IConfig from './interface/iconfig';
1+
// import type IConfig from './interface/iconfig';
22
import type { IStorageProvider } from './storage_provider';
33

44
export class Utils {
55
private static storage: IStorageProvider;
6-
private static config: IConfig;
6+
// private static config: IConfig;
77

8-
static setConfig(config: IConfig) {
9-
Utils.config = config;
10-
}
8+
// static setConfig(config: IConfig) {
9+
// Utils.config = config;
10+
// }
1111

1212
static setStorageProvider(storage: IStorageProvider) {
1313
Utils.storage = storage;

0 commit comments

Comments
 (0)