Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new expo app for react native #188

Merged
merged 7 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions sandboxes/IntercomExpo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files

# dependencies
node_modules/

# android and iOS folders
android/
ios/

# Expo
.expo/
dist/
web-build/

# Native
*.orig.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision

# Metro
.metro-health-check*

# debug
npm-debug.*
yarn-debug.*
yarn-error.*

# macOS
.DS_Store
*.pem

# local env files
.env*.local

# typescript
*.tsbuildinfo
69 changes: 69 additions & 0 deletions sandboxes/IntercomExpo/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, { useEffect } from 'react';
import { StatusBar } from 'expo-status-bar';
import {
StyleSheet,
AppState,
Text,
TextInput,
TouchableOpacity,
View,
} from 'react-native';
import Intercom, { Visibility } from '@intercom/intercom-react-native';
import { useIntercom } from './useIntercom';
import { styles } from './App.styles';

export default function App() {
useEffect(() => {
const subscription = AppState.addEventListener(
'change',
(nextStatus) => nextStatus === 'active' && Intercom.handlePushMessage()
);
return subscription.remove;
}, []);

useEffect(() => {
(async () => {
await Intercom.setLauncherVisibility(Visibility.VISIBLE);
})();
}, []);

const {
handleLoginIdentifiedUser,
handleLoginUnidentifiedUser,
handleLogout,
setUserIdentifier,
isLoggedIn,
} = useIntercom();

return (
<View style={styles.screenWrapper}>
<Text style={styles.title}>Push Notifications Sandbox</Text>
<View style={styles.wrapper}>
{!isLoggedIn ? (
<>
<TextInput style={styles.input} onChangeText={setUserIdentifier} />
<TouchableOpacity
style={styles.button}
onPress={handleLoginIdentifiedUser}
>
<Text style={styles.buttonText}>Login Identified User</Text>
</TouchableOpacity>

<View style={styles.divider} />

<TouchableOpacity
style={styles.button}
onPress={handleLoginUnidentifiedUser}
>
<Text style={styles.buttonText}>Login Unidentified User</Text>
</TouchableOpacity>
</>
) : (
<TouchableOpacity style={styles.button} onPress={handleLogout}>
<Text style={styles.buttonText}>Logout</Text>
</TouchableOpacity>
)}
</View>
</View>
);
}
39 changes: 39 additions & 0 deletions sandboxes/IntercomExpo/App.styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { StyleSheet } from 'react-native';

export const styles = StyleSheet.create({
screenWrapper: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
title: {
position: 'absolute',
top: '25%',
fontWeight: 'bold',
fontSize: 20,
},
wrapper: {
width: '50%',
},
input: {
borderWidth: 1,
borderColor: 'rgba(0,0,80,0.2)',
backgroundColor: '#f3f8ff',
paddingVertical: 10,
fontSize: 18,
marginBottom: 10,
},
button: {
backgroundColor: '#7284c5',
paddingVertical: 13,
alignItems: 'center',
},
buttonText: {
color: '#fff',
},
divider: {
marginVertical: 18,
borderWidth: 0.5,
borderColor: '#5757ca',
},
});
3 changes: 3 additions & 0 deletions sandboxes/IntercomExpo/App.utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { MMKVLoader } from 'react-native-mmkv-storage';

export const storage = new MMKVLoader().initialize();
73 changes: 73 additions & 0 deletions sandboxes/IntercomExpo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Intercom React Native Expo Sandbox

# Setup

## Step 1: Install dependencies

```shell
# using npm
npm install

# OR using Yarn
yarn install
```

## Step 2: Add your app id and api keys

Go to `app.json` and replace the `appId`, `androidApiKey` and `iosApiKey` under `plugins`.
You can also change the intercomRegion to US, EU or AU.
Check our docs for a detailed explanation about these fields [here](https://developers.intercom.com/installing-intercom/react-native/installation/#using-intercom-with-expo)

```shell
"plugins": [
[
"@intercom/intercom-react-native",
{
"appId": "<app-id>",
"androidApiKey": "<android-api-key>",
"iosApiKey": "<ios-api-key>",
"intercomRegion": "US"
}
]
],
```

## Step 3: Prebuild the app

```shell
# using npx
npx expo prebuild

# OR using Yarn
yarn expo prebuild
```

## Step 4: Run pod install

Go to the `ios` folder and run pod install

```shell
npx pod install
```

## Step 5: Run the app

### For Android

```shell
# using npm
npx expo run:android

# OR using Yarn
yarn expo run:android
```

### For iOS

```shell
# using npm
npx expo run:ios

# OR using Yarn
yarn expo run:ios
```
55 changes: 55 additions & 0 deletions sandboxes/IntercomExpo/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"expo": {
"plugins": [
[
"@intercom/intercom-react-native",
{
"appId": "<app-id>",
"androidApiKey": "<android-api-key>",
"iosApiKey": "<ios-api-key>",
"intercomRegion": "US"
}
],
[
"expo-build-properties",
{
"ios": {
"deploymentTarget": "15.0"
}
}
]
],
"name": "IntercomExpo",
"slug": "IntercomExpo",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "io.intercom.ios.enterprise.sample"
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
},
"permissions": [
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.VIBRATE"
],
"package": "com.intercom.sample"
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}
Binary file added sandboxes/IntercomExpo/assets/adaptive-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sandboxes/IntercomExpo/assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sandboxes/IntercomExpo/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sandboxes/IntercomExpo/assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions sandboxes/IntercomExpo/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
Loading