Skip to content

Commit

Permalink
Release version 7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hokstuff committed Sep 12, 2023
1 parent 209dc58 commit 4ef01ed
Show file tree
Hide file tree
Showing 28 changed files with 804 additions and 294 deletions.
96 changes: 93 additions & 3 deletions BrazeProject/BrazeProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Alert,
TextInput,
Platform,
Settings,
} from 'react-native';
import RadioGroup from 'react-native-radio-buttons-group';
import Braze, { BrazeInAppMessage } from '@braze/react-native-sdk';
Expand All @@ -18,6 +19,9 @@ import Braze, { BrazeInAppMessage } from '@braze/react-native-sdk';
// and impressions for in-app messages and content cards.
const automaticallyInteract = false;

// User Defaults keys
const iOSPushAutoEnabledKey = "iOSPushAutoEnabled";

const Space = () => {
return <View style={styles.spacing} />;
};
Expand All @@ -37,6 +41,14 @@ export const BrazeProject = (): ReactElement => {
useState<string>('bool');
const [featureFlagPropertyKey, setFeatureFlagPropertyKey] = useState('');

// If key is persisted, use the value. If no key is present, default to true.
const [iOSPushAutoEnabled, setiOSPushAutoEnabled] = useState<boolean>(
() => {
const value = Settings.get(iOSPushAutoEnabledKey);
return (value != null) ? Boolean(value) : true;
}
);

const subscriptionStateButtons = useMemo(
() => [
{
Expand Down Expand Up @@ -122,13 +134,13 @@ export const BrazeProject = (): ReactElement => {
]);
};

const showToast = (msg: string) => {
const showToast = (msg: string, duration: number = 2000) => {
setMessage(msg);
setToastVisible(true);
setTimeout(() => {
setToastVisible(false);
setMessage('Success');
}, 2000);
}, duration);
};

useEffect(() => {
Expand Down Expand Up @@ -358,10 +370,20 @@ export const BrazeProject = (): ReactElement => {
Braze.setCustomUserAttribute('intattr', 88);
Braze.setCustomUserAttribute('booleanattr', true);
Braze.setCustomUserAttribute('dateattr', new Date());
Braze.setCustomUserAttribute('arrayattr', ['a', 'b']);
Braze.setCustomUserAttribute('stringArrayAttr', ['a', 'b']);
Braze.setCustomUserAttribute('arrayOfObjectsAttr', [{ 'one': 1, 'two': 'too' }, { 'three': 3, 'four': 'fore' }]);
Braze.setCustomUserAttribute('objectAttr', { 'one': 1, 'two': 'too' }, false);
Braze.setCustomUserAttribute('badArray', ['123', { 'one': 1, 'two': 2 }]);
Braze.setCustomUserAttribute('badArray2', [true, 1, 'string', { 'one': 1 }]);
showToast('Custom attributes set');
};

const logCustomAttributeWithMergePress = () => {
Braze.setCustomUserAttribute('objectAttr', { 'three': 3, 'four': 'fore' }, true);
Braze.setCustomUserAttribute('objectAttr', { 'two': 'updated_too' }, true);
showToast('NCA with merge called');
};

const logUserPropertiesPress = () => {
Braze.setFirstName('Brian');
Braze.setLastName('Wheeler');
Expand Down Expand Up @@ -396,6 +418,15 @@ export const BrazeProject = (): ReactElement => {
showToast('Feature Flags refresh requested');
};

const logFeatureFlagImpressionPress = () => {
if (!featureFlagId) {
console.log('No Feature Flag ID entered. Not logging Feature Flag Impression.');
return;
}
Braze.logFeatureFlagImpression(featureFlagId);
showToast(`Feature Flag Impression logged for ID: ${featureFlagId}`);
};

const unsetCustomUserAttributePress = () => {
Braze.unsetCustomUserAttribute('sk');
showToast('Custom attribute unset');
Expand Down Expand Up @@ -499,6 +530,14 @@ export const BrazeProject = (): ReactElement => {
showToast('Geofences Requested');
};

const setLastKnownLocation = () => {
Braze.setLastKnownLocation(40.7128, 74.0060, 23.0, 25.0, 19.0);
Braze.setLastKnownLocation(40.7128, 74.0060, null, null, null);
Braze.setLastKnownLocation(40.7128, 74.0060, null, 25.0, null);
Braze.setLastKnownLocation(40.7128, 74.0060, 23.0, 25.0, null);
showToast('Last known location set');
}

const setLocationCustomAttribute = () => {
Braze.setLocationCustomAttribute('work', 40.7128, 74.006);
showToast('Location Set');
Expand Down Expand Up @@ -544,15 +583,50 @@ export const BrazeProject = (): ReactElement => {
for (const card of cards) {
const cardId = card.id;
console.log(`Got content card: ${JSON.stringify(card)}`);

// Programmatically log impression, card click, and dismissal
if (automaticallyInteract) {
console.log('Automatically logging CC click and impression.');
Braze.logContentCardClicked(cardId);
Braze.logContentCardImpression(cardId);
// To automate card dismissal, uncomment out the code below
// Braze.logContentCardDismissed(cardId);
}
}
};

const getCachedContentCards = async () => {
const cards = await Braze.getCachedContentCards();
console.log(`${cards.length} cached Content Cards found.`);
if (cards.length === 0) {
return;
}

for (const card of cards) {
const cardId = card.id;
console.log(`Got content card from cache: ${JSON.stringify(card)}`);

// Programmatically log impression, card click, and dismissal
if (automaticallyInteract) {
console.log(`Automatically logging CC click and impression for card ID: ${cardId}.`);
Braze.logContentCardClicked(cardId);
Braze.logContentCardImpression(cardId);
// To automate card dismissal, uncomment out the code below
// Braze.logContentCardDismissed(cardId);
}
}
};

// Update value, then store in NSUserDefaults to fetch in iOS layer
const toggleiOSPushAutoEnabled = () => {
const updatedValue = !iOSPushAutoEnabled;
setiOSPushAutoEnabled(updatedValue);
Settings.set({ iOSPushAutoEnabledKey: updatedValue });

console.log(`iOS Push Auto enabled: ${updatedValue}`);
showToast(`iOS Push Automation: ${updatedValue}.\n Restart your app to take effect.`, 4000);
};

const requestPushPermission = () => {
const options = {
alert: true,
Expand Down Expand Up @@ -636,6 +710,7 @@ export const BrazeProject = (): ReactElement => {
</View>

{/* Events */}

<View style={styles.row}>
<TextInput
style={styles.textInput}
Expand Down Expand Up @@ -719,6 +794,9 @@ export const BrazeProject = (): ReactElement => {
<TouchableHighlight onPress={logCustomAttributePress}>
<Text>Set Custom User Attributes</Text>
</TouchableHighlight>
<TouchableHighlight onPress={logCustomAttributeWithMergePress}>
<Text>Set Custom User Attributes with NCA Merge</Text>
</TouchableHighlight>
<TouchableHighlight onPress={unsetCustomUserAttributePress}>
<Text>Unset Custom User Attributes</Text>
</TouchableHighlight>
Expand Down Expand Up @@ -747,6 +825,9 @@ export const BrazeProject = (): ReactElement => {
<TouchableHighlight onPress={getContentCards}>
<Text>Get Content Cards {'&'} Log interactions</Text>
</TouchableHighlight>
<TouchableHighlight onPress={getCachedContentCards}>
<Text>Get Cached Content Cards {'&'} Log interactions</Text>
</TouchableHighlight>

{/* News Feed */}

Expand All @@ -764,6 +845,9 @@ export const BrazeProject = (): ReactElement => {
<TouchableHighlight onPress={refreshFeatureFlagsPress}>
<Text>Refresh Feature Flags</Text>
</TouchableHighlight>
<TouchableHighlight onPress={logFeatureFlagImpressionPress}>
<Text>Log Feature Flag Impression</Text>
</TouchableHighlight>
<TouchableHighlight onPress={getFeatureFlagsPress}>
<Text>Get All Feature Flags</Text>
</TouchableHighlight>
Expand Down Expand Up @@ -811,13 +895,19 @@ export const BrazeProject = (): ReactElement => {
<TouchableHighlight onPress={requestGeofences}>
<Text>Request Geofences</Text>
</TouchableHighlight>
<TouchableHighlight onPress={setLastKnownLocation}>
<Text>Set Last Known Location</Text>
</TouchableHighlight>
<TouchableHighlight onPress={setLocationCustomAttribute}>
<Text>Set Custom Location Attribute</Text>
</TouchableHighlight>

{/* Other */}

<Space />
<TouchableHighlight onPress={toggleiOSPushAutoEnabled}>
<Text>Toggle iOS Push Automation enabled</Text>
</TouchableHighlight>
<TouchableHighlight onPress={requestPushPermission}>
<Text>Request Push Permission</Text>
</TouchableHighlight>
Expand Down
6 changes: 3 additions & 3 deletions BrazeProject/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GEM
specs:
CFPropertyList (3.0.6)
rexml
activesupport (7.0.4.3)
activesupport (7.0.7.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down Expand Up @@ -62,10 +62,10 @@ GEM
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.12.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.6.3)
minitest (5.18.0)
minitest (5.19.0)
molinillo (0.8.0)
nanaimo (0.3.0)
nap (1.1.0)
Expand Down
1 change: 1 addition & 0 deletions BrazeProject/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
apply plugin: "kotlin-android"

import com.android.build.OutputFile

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
*
* This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*/
package com.brazeproject

import android.content.Context
import com.facebook.flipper.android.AndroidFlipperClient
import com.facebook.flipper.android.utils.FlipperUtils
import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin
import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin
import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin
import com.facebook.flipper.plugins.inspector.DescriptorMapping
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin
import com.facebook.react.ReactInstanceEventListener
import com.facebook.react.ReactInstanceManager
import com.facebook.react.bridge.ReactContext
import com.facebook.react.modules.network.NetworkingModule

/**
* Class responsible of loading Flipper inside your React Native application. This is the debug
* flavor of it. Here you can add your own plugins and customize the Flipper setup.
*/
object ReactNativeFlipper {
@JvmStatic
fun initializeFlipper(context: Context?, reactInstanceManager: ReactInstanceManager) {
if (FlipperUtils.shouldEnableFlipper(context)) {
val client = AndroidFlipperClient.getInstance(context)
client.addPlugin(InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()))
client.addPlugin(DatabasesFlipperPlugin(context))
client.addPlugin(SharedPreferencesFlipperPlugin(context))
client.addPlugin(CrashReporterPlugin.getInstance())
val networkFlipperPlugin = NetworkFlipperPlugin()
NetworkingModule.setCustomClientBuilder { builder ->
builder.addNetworkInterceptor(
FlipperOkhttpInterceptor(networkFlipperPlugin)
)
}
client.addPlugin(networkFlipperPlugin)
client.start()

// Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
// Hence we run if after all native modules have been initialized
val reactContext = reactInstanceManager.currentReactContext
if (reactContext == null) {
reactInstanceManager.addReactInstanceEventListener(
object : ReactInstanceEventListener {
override fun onReactContextInitialized(reactContext: ReactContext) {
reactInstanceManager.removeReactInstanceEventListener(this)
reactContext.runOnNativeModulesQueueThread {
client.addPlugin(
FrescoFlipperPlugin()
)
}
}
})
} else {
client.addPlugin(FrescoFlipperPlugin())
}
}
}
}
Loading

0 comments on commit 4ef01ed

Please sign in to comment.