Skip to content
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: 21 additions & 18 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,14 @@ jobs:
fi
echo "✓ Updated Package.swift with iOS SDK ${VERSION}"

PODFILE=examples/demo/ios/Podfile
sed -i '' -E "s/^([[:space:]]*pod 'OneSignalXCFramework', )'[^']+'.*$/\1'${VERSION}'/" "$PODFILE"
if [ "$(grep -c "pod 'OneSignalXCFramework', '${VERSION}'$" "$PODFILE")" -ne 2 ]; then
echo "::error::Failed to update OneSignalXCFramework pins in ${PODFILE} to ${VERSION}"
exit 1
fi
echo "✓ Updated ${PODFILE} extension pods to iOS SDK ${VERSION}"
for PODFILE in examples/demo/ios/Podfile examples/demo-pods/ios/Podfile; do
sed -i '' -E "s/^([[:space:]]*pod 'OneSignalXCFramework', )'[^']+'.*$/\1'${VERSION}'/" "$PODFILE"
if [ "$(grep -c "pod 'OneSignalXCFramework', '${VERSION}'$" "$PODFILE")" -ne 2 ]; then
echo "::error::Failed to update OneSignalXCFramework pins in ${PODFILE} to ${VERSION}"
exit 1
fi
echo "✓ Updated ${PODFILE} extension pods to iOS SDK ${VERSION}"
done

# Only commit if there are changes
git add -A
Expand Down Expand Up @@ -238,17 +239,19 @@ jobs:
# repacked SDK tarball and OneSignalXCFramework pin both reflect
# the new release. setup always runs because every version bump
# changes the tarball integrity recorded in the demo bun.lock.
(cd examples/demo && vp run setup)
echo "✓ Refreshed examples/demo/bun.lock"

if [ -n "$IOS_VERSION" ]; then
(cd examples/demo/ios && pod update OneSignalXCFramework)
else
# Still refresh the local react-native-onesignal pod's version and
# checksum; pod install keeps OneSignalXCFramework at its locked version.
(cd examples/demo/ios && pod install)
fi
echo "✓ Refreshed examples/demo/ios/Podfile.lock"
for DEMO in examples/demo examples/demo-pods; do
(cd "$DEMO" && vp run setup)
echo "✓ Refreshed ${DEMO}/bun.lock"

if [ -n "$IOS_VERSION" ]; then
(cd "$DEMO/ios" && pod update OneSignalXCFramework)
else
# Still refresh the local react-native-onesignal pod's version and
# checksum; pod install keeps OneSignalXCFramework at its locked version.
(cd "$DEMO/ios" && pod install)
fi
echo "✓ Refreshed ${DEMO}/ios/Podfile.lock"
done

# Only commit if there are changes
git add -A
Expand Down
53 changes: 53 additions & 0 deletions __tests__/demoSync.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/// <reference types="node" />

import { readdirSync, readFileSync } from 'node:fs';
import path from 'node:path';

import { expect, test } from 'vite-plus/test';

// demo-pods is demo's iOS app on CocoaPods; its JavaScript must not drift from demo.
const examples = path.resolve(import.meta.dirname, '../examples');
const demo = path.join(examples, 'demo');
const demoPods = path.join(examples, 'demo-pods');
const sharedPaths = [
'App.tsx',
'index.js',
'app.json',
'babel.config.js',
'src',
'assets',
'types',
];

function listFiles(root: string, relative: string): string[] {
const full = path.join(root, relative);
try {
return readdirSync(full, { withFileTypes: true }).flatMap((entry) =>
listFiles(root, path.join(relative, entry.name)),
);
} catch {
return [relative];
}
}

const sharedFiles = (root: string) => sharedPaths.flatMap((p) => listFiles(root, p)).sort();

test('demo-pods has the same JavaScript files as demo', () => {
expect(sharedFiles(demoPods)).toEqual(sharedFiles(demo));
});

test.each(sharedFiles(demo))('demo-pods/%s matches demo', (file) => {
expect(readFileSync(path.join(demoPods, file))).toEqual(readFileSync(path.join(demo, file)));
});

test('demo-pods has the same dependencies as demo', () => {
const deps = (root: string) => {
const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8')) as Record<
string,
unknown
>;
return { dependencies: pkg.dependencies, devDependencies: pkg.devDependencies };
};

expect(deps(demoPods)).toEqual(deps(demo));
});
2 changes: 2 additions & 0 deletions examples/demo-pods/.bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1
7 changes: 7 additions & 0 deletions examples/demo-pods/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Required. The Metro bundle fails when this is unset.
ONESIGNAL_APP_ID=
ONESIGNAL_API_KEY=your-onesignal-api-key

# Optional: Android Notification Channel ID for the WITH SOUND test notification.
# Create one in your OneSignal dashboard under Settings > Android Notification Categories.
ONESIGNAL_ANDROID_CHANNEL_ID=
80 changes: 80 additions & 0 deletions examples/demo-pods/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Environment
.env
android/app/google-services.json
.rn-demo-env.stamp

# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
**/.xcode.env.local

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof
.cxx/
*.keystore
!debug.keystore
.kotlin/

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

**/fastlane/report.xml
**/fastlane/Preview.html
**/fastlane/screenshots
**/fastlane/test_output

# Bundle artifact
*.jsbundle

# Ruby / CocoaPods
**/Pods/
/vendor/bundle/

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

# testing
/coverage

# Yarn
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
1 change: 1 addition & 0 deletions examples/demo-pods/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
74 changes: 74 additions & 0 deletions examples/demo-pods/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import React, { useEffect } from 'react';
import { StatusBar, StyleSheet, Text, View } from 'react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';

import OneSignalLogo from './assets/onesignal_logo.svg';
import AppHeader from './src/components/AppHeader';
import { ToastProvider } from './src/components/ToastProvider';
import { OneSignalProvider } from './src/hooks/useOneSignal';
import HomeScreen from './src/screens/HomeScreen';
import SecondaryScreen from './src/screens/SecondaryScreen';
import TooltipHelper from './src/services/TooltipHelper';
import { AppColors } from './src/theme';

const Stack = createNativeStackNavigator();

function App() {
useEffect(() => {
void TooltipHelper.getInstance().init();
}, []);

return (
<SafeAreaProvider>
<StatusBar barStyle="light-content" />
<ToastProvider>
<OneSignalProvider>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
header: (props) => <AppHeader {...props} />,
}}
>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
headerTitle: () => (
<View style={headerStyles.container}>
<OneSignalLogo height={22} width={99} style={headerStyles.logo} />
<Text style={headerStyles.subtitle}>React Native</Text>
</View>
),
}}
/>
<Stack.Screen
name="Secondary"
component={SecondaryScreen}
options={{ title: 'Secondary Activity' }}
/>
</Stack.Navigator>
</NavigationContainer>
</OneSignalProvider>
</ToastProvider>
</SafeAreaProvider>
);
}

const headerStyles = StyleSheet.create({
container: {
flexDirection: 'row',
alignItems: 'center',
},
logo: {
marginRight: 6,
},
subtitle: {
fontSize: 14,
fontWeight: '400',
color: AppColors.white,
},
});

export default App;
17 changes: 17 additions & 0 deletions examples/demo-pods/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
source 'https://rubygems.org'

# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby ">= 2.6.10"

# Exclude problematic versions of cocoapods and activesupport that causes build failures.
gem 'cocoapods', '>= 1.13', '!= 1.15.0', '!= 1.15.1'
gem 'activesupport', '>= 6.1.7.5', '!= 7.1.0'
gem 'xcodeproj', '< 1.26.0'
gem 'concurrent-ruby', '< 1.3.4'

# Ruby 3.4.0 has removed some libraries from the standard library.
gem 'bigdecimal'
gem 'logger'
gem 'benchmark'
gem 'mutex_m'
gem 'nkf'
35 changes: 35 additions & 0 deletions examples/demo-pods/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# OneSignal React Native Demo (CocoaPods)

The [`demo`](../demo) app's iOS build, integrated with CocoaPods. Use it to check the SDK in apps that have not moved to React Native's Swift Package Manager mode.

The JavaScript (`App.tsx`, `src/`, `assets/`, `types/`) must stay identical to `demo`; a test in the repository root fails when they drift. Make JavaScript changes in `demo` and copy them here. There is no Android project here; use `demo` for Android.

## Setup

Install the SDK's dependencies from the repository root, since setup builds and packs the SDK from there:

```sh
vp install
```

Then, in this directory, copy `.env.example` to `.env` and set your credentials as described in the [`demo` README](../demo/README.md#setup). Install CocoaPods on first run:

```sh
bundle install
cd ios && bundle exec pod install && cd ..
```

## Run

```sh
vp run ios
```

## Other scripts

| Script | Purpose |
| -------------------- | --------------------------------------------------------------------- |
| `vp run setup` | Build, pack, and install the SDK into the demo. |
| `vp run start` | Start Metro. |
| `vp run update:pods` | Run `pod update OneSignalXCFramework` after native SDK changes. |
| `vp run clean:ios` | Wipe iOS build outputs and `ios/Pods`. Run `pod install` again after. |
4 changes: 4 additions & 0 deletions examples/demo-pods/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "demo",
"displayName": "OneSignal Demo"
}
Loading
Loading