Skip to content

Commit 8ee3d77

Browse files
authored
chore: Update sample app to ease testing (#279)
1 parent 167d6da commit 8ee3d77

7 files changed

Lines changed: 5897 additions & 793 deletions

File tree

ONBOARDING.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,25 @@ The sample app is a great way to test your changes and see the SDK in action.
5050
cd sample
5151
```
5252

53-
2. Install JavaScript dependencies:
53+
2. Install dependencies (iOS pods are installed automatically via postinstall):
5454

5555
```bash
5656
yarn install
5757
```
5858

59-
3. Install iOS dependencies:
60-
61-
```bash
62-
cd ios
63-
pod install
64-
cd ..
65-
```
66-
67-
4. Start the Metro bundler:
59+
3. Start the Metro bundler:
6860

6961
```bash
7062
yarn start
7163
```
7264

73-
5. Open the iOS workspace:
65+
4. Open the iOS workspace:
7466

7567
```bash
7668
open ios/MParticleSample.xcworkspace
7769
```
7870

79-
6. In Xcode:
71+
5. In Xcode:
8072
- Select your target device/simulator
8173
- Update signing configuration if needed
8274
- Build and run (⌘R)

sample/index.js

Lines changed: 153 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import {
1414
findNodeHandle,
1515
ScrollView,
1616
NativeEventEmitter,
17+
SafeAreaView,
18+
TextInput,
19+
View,
20+
TouchableOpacity,
21+
KeyboardAvoidingView,
1722
} from 'react-native';
1823
import MParticle from 'react-native-mparticle';
1924

@@ -25,11 +30,14 @@ export default class MParticleSample extends Component {
2530
constructor(props) {
2631
super(props);
2732
this.placeholder1 = React.createRef();
28-
this.state = {isShowingText: true,
33+
this.state = {
34+
isShowingText: true,
2935
optedOut: true,
3036
attributionResults: "{value: no attributionResults}",
3137
session: '',
32-
isKitActive: true};
38+
isKitActive: true,
39+
customIdentifier: 'MSDKBottomSheetLayout',
40+
};
3341

3442
this._toggleOptOut = this._toggleOptOut.bind(this)
3543
this._getAttributionResults = this._getAttributionResults.bind(this)
@@ -235,67 +243,162 @@ export default class MParticleSample extends Component {
235243
let optAction = this.state.optedOut ? 'In' : 'Out'
236244
let kitActive = this.state.isKitActive ? 'true' : 'false'
237245
return (
238-
<ScrollView contentContainerStyle={styles.container}>
239-
<Text style={styles.welcome}>
240-
Welcome to React Native! {display}
241-
</Text>
242-
<Text style={styles.welcome}>
243-
Opted Out = {optedOut}
244-
</Text>
245-
<Button
246-
onPress={() => {this._toggleOptOut()}}
247-
title={'Opt ' + optAction}/>
248-
<Text>
249-
Session = {JSON.stringify(this.state.session)}
250-
</Text>
251-
<Text>
252-
Attributes = {JSON.stringify(this.state.attributionResults)}
253-
</Text>
254-
<Button
255-
onPress={() => {this._getAttributionResults()}}
256-
title="Get Attribution Results"/>
257-
<Text>
258-
KitActive = {kitActive} (should switch to false)
259-
</Text>
260-
<Button
261-
onPress={() => {this._isKitActive()}}
262-
title="Check Kit Active"/>
263-
<Text style={styles.instructions}>
264-
To get started, edit index.js
265-
</Text>
266-
<Text style={styles.instructions}>
267-
Press Cmd+R to reload,{'\n'}
268-
Cmd+D or shake for dev menu
269-
</Text>
246+
<SafeAreaView style={styles.safeArea}>
247+
<KeyboardAvoidingView
248+
style={styles.keyboardAvoid}
249+
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
250+
>
251+
<ScrollView contentContainerStyle={styles.container} keyboardShouldPersistTaps="handled">
252+
<View style={styles.header}>
253+
<Text style={styles.logo}>mParticle</Text>
254+
<Text style={styles.subtitle}>React Native SDK Sample</Text>
255+
</View>
256+
<Text style={styles.statusText}>
257+
{display}
258+
</Text>
259+
<Text style={styles.infoText}>
260+
Opted Out = {optedOut}
261+
</Text>
262+
<Button
263+
onPress={() => {this._toggleOptOut()}}
264+
title={'Opt ' + optAction}/>
265+
<Text style={styles.infoText}>
266+
Session = {JSON.stringify(this.state.session)}
267+
</Text>
268+
<Text style={styles.infoText}>
269+
Attributes = {JSON.stringify(this.state.attributionResults)}
270+
</Text>
271+
<Button
272+
onPress={() => {this._getAttributionResults()}}
273+
title="Get Attribution Results"/>
274+
<Text style={styles.infoText}>
275+
KitActive = {kitActive} (should switch to false)
276+
</Text>
277+
<Button
278+
onPress={() => {this._isKitActive()}}
279+
title="Check Kit Active"/>
280+
<Text style={styles.instructions}>
281+
To get started, edit index.js
282+
</Text>
283+
<Text style={styles.instructions}>
284+
Press Cmd+R to reload,{'\n'}
285+
Cmd+D or shake for dev menu
286+
</Text>
270287

271-
<Button
272-
onPress={() => {this._incrementAttribute()}}
273-
title="Increment Attribute"/>
274-
<Text style={styles.instructions}>ROKT</Text>
275-
<Button title="ROKT Embedded" onPress={() => {this._roktSelectEmbeddedPlacements()}}/>
276-
<Button title="ROKT Overlay" onPress={() => {this._roktSelectOverlayPlacements()}}/>
277-
<Button title="ROKT BottomSheet" onPress={() => {this._roktSelectBottomSheetPlacements()}}/>
278-
<RoktLayoutView
279-
ref={this.placeholder1}
280-
placeholderName="Location1" />
281-
</ScrollView>
288+
<Button
289+
onPress={() => {this._incrementAttribute()}}
290+
title="Increment Attribute"/>
291+
<Text style={styles.sectionTitle}>ROKT</Text>
292+
<Button title="ROKT Embedded" onPress={() => {this._roktSelectEmbeddedPlacements()}}/>
293+
<Button title="ROKT Overlay" onPress={() => {this._roktSelectOverlayPlacements()}}/>
294+
<Button title="ROKT BottomSheet" onPress={() => {this._roktSelectBottomSheetPlacements()}}/>
295+
296+
<View style={styles.section}>
297+
<Text style={styles.sectionTitle}>Custom Placement</Text>
298+
<TextInput
299+
style={styles.textInput}
300+
value={this.state.customIdentifier}
301+
onChangeText={(text) => this.setState({ customIdentifier: text })}
302+
placeholder="Enter placement identifier"
303+
placeholderTextColor="#999"
304+
/>
305+
<TouchableOpacity
306+
style={styles.primaryButton}
307+
onPress={() => this._roktSelectPlacements(this.state.customIdentifier)}
308+
>
309+
<Text style={styles.primaryButtonText}>Run Custom Placement</Text>
310+
</TouchableOpacity>
311+
</View>
312+
313+
<RoktLayoutView
314+
ref={this.placeholder1}
315+
placeholderName="Location1" />
316+
</ScrollView>
317+
</KeyboardAvoidingView>
318+
</SafeAreaView>
282319
);
283320
}
284321
}
285322

286323
const styles = StyleSheet.create({
324+
safeArea: {
325+
flex: 1,
326+
backgroundColor: '#FFFFFF',
327+
},
328+
keyboardAvoid: {
329+
flex: 1,
330+
},
287331
container: {
288332
flexGrow: 1,
289-
backgroundColor: '#F5FCFF',
333+
padding: 20,
334+
backgroundColor: '#FFFFFF',
335+
},
336+
header: {
337+
alignItems: 'center',
338+
marginBottom: 20,
339+
paddingVertical: 15,
340+
borderBottomWidth: 1,
341+
borderBottomColor: '#E0E0E0',
342+
},
343+
logo: {
344+
fontSize: 32,
345+
fontWeight: 'bold',
346+
color: '#C20075', // Beetroot
347+
},
348+
subtitle: {
349+
fontSize: 16,
350+
color: '#666666',
351+
marginTop: 4,
290352
},
291-
welcome: {
292-
fontSize: 20,
353+
statusText: {
293354
textAlign: 'center',
294-
margin: 10,
355+
fontSize: 14,
356+
color: '#000000',
357+
marginBottom: 20,
358+
},
359+
section: {
360+
marginVertical: 15,
361+
padding: 15,
362+
backgroundColor: '#F8F8F8',
363+
borderRadius: 10,
364+
},
365+
sectionTitle: {
366+
fontSize: 16,
367+
fontWeight: '600',
368+
color: '#000000',
369+
marginBottom: 10,
370+
textAlign: 'center',
371+
},
372+
textInput: {
373+
borderWidth: 1,
374+
borderColor: '#E0E0E0',
375+
borderRadius: 8,
376+
padding: 12,
377+
fontSize: 14,
378+
backgroundColor: '#FFFFFF',
379+
marginBottom: 10,
380+
color: '#000000',
381+
},
382+
primaryButton: {
383+
backgroundColor: '#C20075', // Beetroot
384+
paddingVertical: 12,
385+
paddingHorizontal: 20,
386+
borderRadius: 8,
387+
alignItems: 'center',
388+
},
389+
primaryButtonText: {
390+
color: '#FFFFFF',
391+
fontSize: 16,
392+
fontWeight: '600',
393+
},
394+
infoText: {
395+
fontSize: 14,
396+
color: '#666666',
397+
marginVertical: 5,
295398
},
296399
instructions: {
297400
textAlign: 'center',
298-
color: '#333333',
401+
color: '#666666',
299402
marginBottom: 5,
300403
},
301404
});

sample/ios/MParticleSample.xcodeproj/project.pbxproj

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,14 @@
277277
inputFileListPaths = (
278278
"${PODS_ROOT}/Target Support Files/Pods-MParticleSample/Pods-MParticleSample-frameworks-${CONFIGURATION}-input-files.xcfilelist",
279279
);
280+
inputPaths = (
281+
);
280282
name = "[CP] Embed Pods Frameworks";
281283
outputFileListPaths = (
282284
"${PODS_ROOT}/Target Support Files/Pods-MParticleSample/Pods-MParticleSample-frameworks-${CONFIGURATION}-output-files.xcfilelist",
283285
);
286+
outputPaths = (
287+
);
284288
runOnlyForDeploymentPostprocessing = 0;
285289
shellPath = /bin/sh;
286290
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MParticleSample/Pods-MParticleSample-frameworks.sh\"\n";
@@ -338,10 +342,14 @@
338342
inputFileListPaths = (
339343
"${PODS_ROOT}/Target Support Files/Pods-MParticleSample-MParticleSampleTests/Pods-MParticleSample-MParticleSampleTests-frameworks-${CONFIGURATION}-input-files.xcfilelist",
340344
);
345+
inputPaths = (
346+
);
341347
name = "[CP] Embed Pods Frameworks";
342348
outputFileListPaths = (
343349
"${PODS_ROOT}/Target Support Files/Pods-MParticleSample-MParticleSampleTests/Pods-MParticleSample-MParticleSampleTests-frameworks-${CONFIGURATION}-output-files.xcfilelist",
344350
);
351+
outputPaths = (
352+
);
345353
runOnlyForDeploymentPostprocessing = 0;
346354
shellPath = /bin/sh;
347355
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MParticleSample-MParticleSampleTests/Pods-MParticleSample-MParticleSampleTests-frameworks.sh\"\n";
@@ -355,10 +363,14 @@
355363
inputFileListPaths = (
356364
"${PODS_ROOT}/Target Support Files/Pods-MParticleSample/Pods-MParticleSample-resources-${CONFIGURATION}-input-files.xcfilelist",
357365
);
366+
inputPaths = (
367+
);
358368
name = "[CP] Copy Pods Resources";
359369
outputFileListPaths = (
360370
"${PODS_ROOT}/Target Support Files/Pods-MParticleSample/Pods-MParticleSample-resources-${CONFIGURATION}-output-files.xcfilelist",
361371
);
372+
outputPaths = (
373+
);
362374
runOnlyForDeploymentPostprocessing = 0;
363375
shellPath = /bin/sh;
364376
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MParticleSample/Pods-MParticleSample-resources.sh\"\n";
@@ -372,10 +384,14 @@
372384
inputFileListPaths = (
373385
"${PODS_ROOT}/Target Support Files/Pods-MParticleSample-MParticleSampleTests/Pods-MParticleSample-MParticleSampleTests-resources-${CONFIGURATION}-input-files.xcfilelist",
374386
);
387+
inputPaths = (
388+
);
375389
name = "[CP] Copy Pods Resources";
376390
outputFileListPaths = (
377391
"${PODS_ROOT}/Target Support Files/Pods-MParticleSample-MParticleSampleTests/Pods-MParticleSample-MParticleSampleTests-resources-${CONFIGURATION}-output-files.xcfilelist",
378392
);
393+
outputPaths = (
394+
);
379395
runOnlyForDeploymentPostprocessing = 0;
380396
shellPath = /bin/sh;
381397
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MParticleSample-MParticleSampleTests/Pods-MParticleSample-MParticleSampleTests-resources.sh\"\n";
@@ -470,6 +486,7 @@
470486
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
471487
CLANG_ENABLE_MODULES = YES;
472488
CURRENT_PROJECT_VERSION = 1;
489+
DEVELOPMENT_TEAM = DLD43Y3TRP;
473490
ENABLE_BITCODE = NO;
474491
INFOPLIST_FILE = MParticleSample/Info.plist;
475492
IPHONEOS_DEPLOYMENT_TARGET = 15.1;
@@ -498,6 +515,7 @@
498515
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
499516
CLANG_ENABLE_MODULES = YES;
500517
CURRENT_PROJECT_VERSION = 1;
518+
DEVELOPMENT_TEAM = DLD43Y3TRP;
501519
INFOPLIST_FILE = MParticleSample/Info.plist;
502520
IPHONEOS_DEPLOYMENT_TARGET = 15.1;
503521
LD_RUNPATH_SEARCH_PATHS = (
@@ -586,10 +604,7 @@
586604
"-DFOLLY_CFG_NO_COROUTINES=1",
587605
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
588606
);
589-
OTHER_LDFLAGS = (
590-
"$(inherited)",
591-
" ",
592-
);
607+
OTHER_LDFLAGS = "$(inherited) ";
593608
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
594609
SDKROOT = iphoneos;
595610
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
@@ -658,10 +673,7 @@
658673
"-DFOLLY_CFG_NO_COROUTINES=1",
659674
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
660675
);
661-
OTHER_LDFLAGS = (
662-
"$(inherited)",
663-
" ",
664-
);
676+
OTHER_LDFLAGS = "$(inherited) ";
665677
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
666678
SDKROOT = iphoneos;
667679
USE_HERMES = true;

sample/ios/MParticleSample/AppDelegate.mm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
1818
{
1919
self.moduleName = @"MParticleSample";
2020
self.initialProps = @{};
21-
MParticleOptions *mParticleOptions = [MParticleOptions optionsWithKey:@"REPLACE ME"
22-
secret:@"REPLACE ME"];
21+
22+
MPNetworkOptions *networkOptions = [[MPNetworkOptions alloc] init];
23+
networkOptions.pinningDisabled = true;
24+
25+
MParticleOptions *mParticleOptions = [MParticleOptions optionsWithKey:@"REPLACE_ME"
26+
secret:@"REPLACE_ME"];
27+
mParticleOptions.logLevel = MPILogLevelDebug;
28+
mParticleOptions.environment = MPEnvironmentProduction;
29+
2330
//Please see the Identity page for more information on building this object
2431
MPIdentityApiRequest *request = [MPIdentityApiRequest requestWithEmptyUser];
2532
request.email = @"email@example.com";

0 commit comments

Comments
 (0)