Skip to content

Commit d20c738

Browse files
simplify example app
1 parent 08f9b62 commit d20c738

File tree

5 files changed

+118
-70
lines changed

5 files changed

+118
-70
lines changed

.eslintrc.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"root": true,
3+
"extends": [
4+
"eslint:recommended",
5+
"plugin:@typescript-eslint/recommended"
6+
],
7+
"parser": "@typescript-eslint/parser",
8+
"parserOptions": { "project": ["./tsconfig.json"] },
9+
"plugins": [
10+
"@typescript-eslint"
11+
],
12+
"rules": {
13+
"@typescript-eslint/strict-boolean-expressions": [
14+
2,
15+
{
16+
"allowString" : false,
17+
"allowNumber" : false
18+
}
19+
]
20+
},
21+
"ignorePatterns": []
22+
}

README.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,64 @@ npm install react-native-sourcepoint-cmp
99
## Usage
1010

1111
```js
12-
import { multiply } from "react-native-sourcepoint-cmp";
12+
//...
1313

14-
// ...
14+
import { SPConsentManager } from 'react-native-sourcepoint-cmp';
1515

16-
const result = await multiply(3, 7);
16+
const config = {
17+
accountId: 22,
18+
propertyId: 999,
19+
propertyName: "mobile.multicampaign.demo",
20+
gdprPMId: "488393",
21+
ccpaPMId: "509688"
22+
}
23+
24+
const consentManager = new SPConsentManager(
25+
config.accountId,
26+
config.propertyId,
27+
config.propertyName
28+
);
29+
30+
export default function App() {
31+
const [userData, setUserData] = React.useState<{}>({});
32+
33+
React.useEffect(() => {
34+
// it's important to wrap `onFinished` and `loadMessage` in a
35+
// useEffect hook so they only get called once.
36+
consentManager.onFinished(() => {
37+
consentManager.getUserData().then(setUserData);
38+
})
39+
consentManager.loadMessage();
40+
consentManager.getUserData().then(setUserData);
41+
}, []);
42+
43+
return (
44+
<SafeAreaView>
45+
<View>
46+
<Button title="Load Messages" onPress={() => {
47+
consentManager.loadMessage();
48+
}}/>
49+
<Button title="Load GDPR PM" onPress={() => {
50+
consentManager.loadGDPRPrivacyManager(config.gdprPMId);
51+
}}/>
52+
<Button title="Load CCPA PM" onPress={() => {
53+
consentManager.loadCCPAPrivacyManager(config.ccpaPMId);
54+
}}/>
55+
<Button title="Clear All" onPress={() => {
56+
consentManager.clearLocalData()
57+
consentManager.getUserData().then(setUserData)
58+
}}/>
59+
</View>
60+
<ScrollView>
61+
<ScrollView horizontal={true}>
62+
<Text>
63+
{JSON.stringify(userData, undefined, ' ')}
64+
</Text>
65+
</ScrollView>
66+
</ScrollView>
67+
</SafeAreaView>
68+
);
69+
}
1770
```
1871

1972
## Contributing

example/index.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
import * as React from 'react';
21
import { AppRegistry } from 'react-native';
32
import App from './src/App';
43

5-
import { SPConsentManager } from 'react-native-sourcepoint-cmp';
6-
7-
const SPConfig = {
8-
accountId: 22,
9-
propertyId: 999,
10-
propertyName: "mobile.multicampaign.demo",
11-
gdprPMId: "488393",
12-
ccpaPMId: "509688"
13-
}
14-
15-
const manager = new SPConsentManager(
16-
SPConfig.accountId,
17-
SPConfig.propertyId,
18-
SPConfig.propertyName
19-
);
20-
21-
const PrivacyCompliantApp = () => <App consentManager={manager} config={SPConfig} />
22-
23-
AppRegistry.registerComponent('main', () => PrivacyCompliantApp);
4+
AppRegistry.registerComponent('main', () => App);

example/src/App.tsx

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
import * as React from 'react';
2-
import { StyleSheet, View, ScrollView, SafeAreaView, Button, Text } from 'react-native';
3-
import JSONTree from 'react-native-json-tree';
2+
import { View, ScrollView, SafeAreaView, Button, Text } from 'react-native';
43

5-
export default function App({ consentManager, config }) {
6-
const [userData, setUserData] = React.useState<{}>({});
4+
import { SPConsentManager } from 'react-native-sourcepoint-cmp';
5+
6+
const config = {
7+
accountId: 22,
8+
propertyId: 999,
9+
propertyName: 'mobile.multicampaign.demo',
10+
gdprPMId: '488393',
11+
ccpaPMId: '509688',
12+
};
13+
14+
const consentManager = new SPConsentManager(
15+
config.accountId,
16+
config.propertyId,
17+
config.propertyName,
18+
);
19+
20+
export default function App() {
21+
const [userData, setUserData] = React.useState<Record<string, unknown>>({});
722

823
React.useEffect(() => {
924
consentManager.onFinished(() => {
@@ -14,51 +29,29 @@ export default function App({ consentManager, config }) {
1429
}, []);
1530

1631
return (
17-
<SafeAreaView style={styles.container}>
18-
<View style={styles.buttonsContainer}>
19-
<Button title="Load Messages" onPress={() => {
32+
<SafeAreaView>
33+
<View>
34+
<Button title='Load Messages' onPress={() => {
2035
consentManager.loadMessage();
2136
}}/>
22-
<Button title="Load GDPR PM" onPress={() => {
37+
<Button title='Load GDPR PM' onPress={() => {
2338
consentManager.loadGDPRPrivacyManager(config.gdprPMId);
2439
}}/>
25-
<Button title="Load CCPA PM" onPress={() => {
40+
<Button title='Load CCPA PM' onPress={() => {
2641
consentManager.loadCCPAPrivacyManager(config.ccpaPMId);
2742
}}/>
28-
<Button title="Clear All" onPress={() => {
43+
<Button title='Clear All' onPress={() => {
2944
consentManager.clearLocalData()
3045
consentManager.getUserData().then(setUserData)
3146
}}/>
3247
</View>
33-
<ScrollView style={styles.dataContainer} horizontal={true} >
34-
<ScrollView>
35-
<JSONTree
36-
data={userData}
37-
labelRenderer={([key, ..._]) => <Text style={{ fontWeight: 'bold', fontSize: 16 }}>{key}</Text>}
38-
valueRenderer={raw => <Text style={{ fontStyle: 'italic', fontSize: 16 }}>{raw}</Text>}
39-
/>
48+
<ScrollView>
49+
<ScrollView horizontal={true}>
50+
<Text>
51+
{JSON.stringify(userData, undefined, ' ')}
52+
</Text>
4053
</ScrollView>
4154
</ScrollView>
4255
</SafeAreaView>
4356
);
4457
}
45-
46-
const styles = StyleSheet.create({
47-
container: {
48-
flex: 1,
49-
alignItems: 'flex-start',
50-
padding: 20,
51-
},
52-
buttonsContainer: {
53-
flex: 1,
54-
alignItems: 'center',
55-
width: '100%',
56-
minHeight: 160,
57-
flexGrow: 0
58-
},
59-
dataContainer: {
60-
flex: 1,
61-
width: '100%',
62-
flexGrow: 1
63-
}
64-
});

src/index.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ const LINKING_ERROR =
66
'- You rebuilt the app after installing the package\n' +
77
'- You are not using Expo managed workflow\n';
88

9-
const SourcepointCmp = NativeModules.SourcepointCmp ? NativeModules.SourcepointCmp : new Proxy(
10-
{},
11-
{
12-
get() {
13-
throw new Error(LINKING_ERROR);
14-
},
15-
}
16-
);
9+
const SourcepointCmp = NativeModules.SourcepointCmp !== undefined ?
10+
NativeModules.SourcepointCmp :
11+
new Proxy({}, {
12+
get() {
13+
throw new Error(LINKING_ERROR);
14+
},
15+
});
1716
export class SPConsentManager {
1817
accountId: number;
1918
propId: number;
@@ -28,12 +27,12 @@ export class SPConsentManager {
2827
this.propName = propName;
2928
}
3029

31-
onFinished(callback: () => any) {
30+
onFinished(callback: () => void) {
3231
this.emitter.removeAllListeners('onSPFinished')
3332
this.emitter.addListener('onSPFinished', callback);
3433
}
3534

36-
getUserData(): Promise<Object> {
35+
getUserData(): Promise<Record<string, unknown>> {
3736
return SourcepointCmp.getUserData();
3837
}
3938

0 commit comments

Comments
 (0)