diff --git a/test/posthog-react-native-session-replay/android/.gradle/8.9/checksums/checksums.lock b/test/posthog-react-native-session-replay/android/.gradle/8.9/checksums/checksums.lock new file mode 100644 index 00000000..af83481b Binary files /dev/null and b/test/posthog-react-native-session-replay/android/.gradle/8.9/checksums/checksums.lock differ diff --git a/test/posthog-react-native-session-replay/android/.gradle/8.9/dependencies-accessors/gc.properties b/test/posthog-react-native-session-replay/android/.gradle/8.9/dependencies-accessors/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/test/posthog-react-native-session-replay/android/.gradle/8.9/executionHistory/executionHistory.lock b/test/posthog-react-native-session-replay/android/.gradle/8.9/executionHistory/executionHistory.lock new file mode 100644 index 00000000..f86ed368 Binary files /dev/null and b/test/posthog-react-native-session-replay/android/.gradle/8.9/executionHistory/executionHistory.lock differ diff --git a/test/posthog-react-native-session-replay/android/.gradle/8.9/fileChanges/last-build.bin b/test/posthog-react-native-session-replay/android/.gradle/8.9/fileChanges/last-build.bin new file mode 100644 index 00000000..f76dd238 Binary files /dev/null and b/test/posthog-react-native-session-replay/android/.gradle/8.9/fileChanges/last-build.bin differ diff --git a/test/posthog-react-native-session-replay/android/.gradle/8.9/fileHashes/fileHashes.lock b/test/posthog-react-native-session-replay/android/.gradle/8.9/fileHashes/fileHashes.lock new file mode 100644 index 00000000..d313805a Binary files /dev/null and b/test/posthog-react-native-session-replay/android/.gradle/8.9/fileHashes/fileHashes.lock differ diff --git a/test/posthog-react-native-session-replay/android/.gradle/8.9/gc.properties b/test/posthog-react-native-session-replay/android/.gradle/8.9/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/test/posthog-react-native-session-replay/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/test/posthog-react-native-session-replay/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 00000000..5351a22d Binary files /dev/null and b/test/posthog-react-native-session-replay/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/test/posthog-react-native-session-replay/android/.gradle/buildOutputCleanup/cache.properties b/test/posthog-react-native-session-replay/android/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 00000000..caf37cac --- /dev/null +++ b/test/posthog-react-native-session-replay/android/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Mon Sep 16 11:59:46 BST 2024 +gradle.version=8.9 diff --git a/test/posthog-react-native-session-replay/android/.gradle/vcs-1/gc.properties b/test/posthog-react-native-session-replay/android/.gradle/vcs-1/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/test/posthog-react-native-session-replay/android/build.gradle b/test/posthog-react-native-session-replay/android/build.gradle new file mode 100644 index 00000000..f9a48aea --- /dev/null +++ b/test/posthog-react-native-session-replay/android/build.gradle @@ -0,0 +1,99 @@ +buildscript { + // Buildscript is evaluated before everything else so we can't use getExtOrDefault + def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["PosthogReactNativeSessionReplay_kotlinVersion"] + + repositories { + google() + mavenCentral() + } + + dependencies { + classpath "com.android.tools.build:gradle:7.2.1" + // noinspection DifferentKotlinGradleVersion + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +def reactNativeArchitectures() { + def value = rootProject.getProperties().get("reactNativeArchitectures") + return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] +} + +def isNewArchitectureEnabled() { + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" +} + +apply plugin: "com.android.library" +apply plugin: "kotlin-android" + +if (isNewArchitectureEnabled()) { + apply plugin: "com.facebook.react" +} + +def getExtOrDefault(name) { + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["PosthogReactNativeSessionReplay_" + name] +} + +def getExtOrIntegerDefault(name) { + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["PosthogReactNativeSessionReplay_" + name]).toInteger() +} + +def supportsNamespace() { + def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') + def major = parsed[0].toInteger() + def minor = parsed[1].toInteger() + + // Namespace support was added in 7.3.0 + return (major == 7 && minor >= 3) || major >= 8 +} + +android { + if (supportsNamespace()) { + namespace "com.posthogreactnativesessionreplay" + + sourceSets { + main { + manifest.srcFile "src/main/AndroidManifestNew.xml" + } + } + } + + compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") + + defaultConfig { + minSdkVersion getExtOrIntegerDefault("minSdkVersion") + targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") + + } + + buildTypes { + release { + minifyEnabled false + } + } + + lintOptions { + disable "GradleCompatible" + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +repositories { + mavenCentral() + google() +} + +def kotlin_version = getExtOrDefault("kotlinVersion") + +dependencies { + // For < 0.71, this will be from the local maven repo + // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin + //noinspection GradleDynamicVersion + implementation "com.facebook.react:react-native:+" + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" +} + diff --git a/test/posthog-react-native-session-replay/android/gradle.properties b/test/posthog-react-native-session-replay/android/gradle.properties new file mode 100644 index 00000000..dbb94542 --- /dev/null +++ b/test/posthog-react-native-session-replay/android/gradle.properties @@ -0,0 +1,5 @@ +PosthogReactNativeSessionReplay_kotlinVersion=1.7.0 +PosthogReactNativeSessionReplay_minSdkVersion=21 +PosthogReactNativeSessionReplay_targetSdkVersion=31 +PosthogReactNativeSessionReplay_compileSdkVersion=31 +PosthogReactNativeSessionReplay_ndkversion=21.4.7075529 diff --git a/test/posthog-react-native-session-replay/android/src/main/AndroidManifest.xml b/test/posthog-react-native-session-replay/android/src/main/AndroidManifest.xml new file mode 100644 index 00000000..63515106 --- /dev/null +++ b/test/posthog-react-native-session-replay/android/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + diff --git a/test/posthog-react-native-session-replay/android/src/main/AndroidManifestNew.xml b/test/posthog-react-native-session-replay/android/src/main/AndroidManifestNew.xml new file mode 100644 index 00000000..a2f47b60 --- /dev/null +++ b/test/posthog-react-native-session-replay/android/src/main/AndroidManifestNew.xml @@ -0,0 +1,2 @@ + + diff --git a/test/posthog-react-native-session-replay/android/src/main/java/com/posthogreactnativesessionreplay/PosthogReactNativeSessionReplayModule.kt b/test/posthog-react-native-session-replay/android/src/main/java/com/posthogreactnativesessionreplay/PosthogReactNativeSessionReplayModule.kt new file mode 100644 index 00000000..6b4c4ecf --- /dev/null +++ b/test/posthog-react-native-session-replay/android/src/main/java/com/posthogreactnativesessionreplay/PosthogReactNativeSessionReplayModule.kt @@ -0,0 +1,25 @@ +package com.posthogreactnativesessionreplay + +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.bridge.ReactContextBaseJavaModule +import com.facebook.react.bridge.ReactMethod +import com.facebook.react.bridge.Promise + +class PosthogReactNativeSessionReplayModule(reactContext: ReactApplicationContext) : + ReactContextBaseJavaModule(reactContext) { + + override fun getName(): String { + return NAME + } + + // Example method + // See https://reactnative.dev/docs/native-modules-android + @ReactMethod + fun multiply(a: Double, b: Double, promise: Promise) { + promise.resolve(a * b) + } + + companion object { + const val NAME = "PosthogReactNativeSessionReplay" + } +} diff --git a/test/posthog-react-native-session-replay/android/src/main/java/com/posthogreactnativesessionreplay/PosthogReactNativeSessionReplayPackage.kt b/test/posthog-react-native-session-replay/android/src/main/java/com/posthogreactnativesessionreplay/PosthogReactNativeSessionReplayPackage.kt new file mode 100644 index 00000000..627546b7 --- /dev/null +++ b/test/posthog-react-native-session-replay/android/src/main/java/com/posthogreactnativesessionreplay/PosthogReactNativeSessionReplayPackage.kt @@ -0,0 +1,17 @@ +package com.posthogreactnativesessionreplay + +import com.facebook.react.ReactPackage +import com.facebook.react.bridge.NativeModule +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.uimanager.ViewManager + + +class PosthogReactNativeSessionReplayPackage : ReactPackage { + override fun createNativeModules(reactContext: ReactApplicationContext): List { + return listOf(PosthogReactNativeSessionReplayModule(reactContext)) + } + + override fun createViewManagers(reactContext: ReactApplicationContext): List> { + return emptyList() + } +} diff --git a/test/posthog-react-native-session-replay/babel.config.js b/test/posthog-react-native-session-replay/babel.config.js new file mode 100644 index 00000000..6b5d2c6c --- /dev/null +++ b/test/posthog-react-native-session-replay/babel.config.js @@ -0,0 +1,3 @@ +module.exports = { + presets: ['module:metro-react-native-babel-preset', '@babel/env', '@babel/preset-typescript'], +} diff --git a/test/posthog-react-native-session-replay/ios/PosthogReactNativeSessionReplay-Bridging-Header.h b/test/posthog-react-native-session-replay/ios/PosthogReactNativeSessionReplay-Bridging-Header.h new file mode 100644 index 00000000..dea7ff6b --- /dev/null +++ b/test/posthog-react-native-session-replay/ios/PosthogReactNativeSessionReplay-Bridging-Header.h @@ -0,0 +1,2 @@ +#import +#import diff --git a/test/posthog-react-native-session-replay/ios/PosthogReactNativeSessionReplay.mm b/test/posthog-react-native-session-replay/ios/PosthogReactNativeSessionReplay.mm new file mode 100644 index 00000000..40687bb7 --- /dev/null +++ b/test/posthog-react-native-session-replay/ios/PosthogReactNativeSessionReplay.mm @@ -0,0 +1,14 @@ +#import + +@interface RCT_EXTERN_MODULE(PosthogReactNativeSessionReplay, NSObject) + +RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b + withResolver:(RCTPromiseResolveBlock)resolve + withRejecter:(RCTPromiseRejectBlock)reject) + ++ (BOOL)requiresMainQueueSetup +{ + return NO; +} + +@end diff --git a/test/posthog-react-native-session-replay/ios/PosthogReactNativeSessionReplay.swift b/test/posthog-react-native-session-replay/ios/PosthogReactNativeSessionReplay.swift new file mode 100644 index 00000000..4d5cca62 --- /dev/null +++ b/test/posthog-react-native-session-replay/ios/PosthogReactNativeSessionReplay.swift @@ -0,0 +1,8 @@ +@objc(PosthogReactNativeSessionReplay) +class PosthogReactNativeSessionReplay: NSObject { + + @objc(multiply:withB:withResolver:withRejecter:) + func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void { + resolve(a*b) + } +} diff --git a/test/posthog-react-native-session-replay/jest.config.js b/test/posthog-react-native-session-replay/jest.config.js new file mode 100644 index 00000000..9f5ffef5 --- /dev/null +++ b/test/posthog-react-native-session-replay/jest.config.js @@ -0,0 +1,16 @@ +module.exports = { + preset: 'jest-expo', + roots: [''], + testEnvironment: 'node', + transform: { + '^.+\\.ts$': 'ts-jest', + }, + moduleFileExtensions: ['ts', 'js', 'json', 'node', 'tsx'], + collectCoverage: true, + clearMocks: true, + coverageDirectory: 'coverage', + testPathIgnorePatterns: ['/lib/', 'node_modules', 'examples'], + fakeTimers: { enableGlobally: true }, + transformIgnorePatterns: [], + } + \ No newline at end of file diff --git a/test/posthog-react-native-session-replay/package.json b/test/posthog-react-native-session-replay/package.json new file mode 100644 index 00000000..69c0e978 --- /dev/null +++ b/test/posthog-react-native-session-replay/package.json @@ -0,0 +1,51 @@ +{ + "name": "posthog-react-native-session-replay", + "version": "0.1.0", + "main": "lib/posthog-react-native-session-replay/index.js", + "files": [ + "src", + "lib", + "android", + "ios", + "cpp", + "*.podspec", + "!ios/build", + "!android/build", + "!android/gradle", + "!android/gradlew", + "!android/gradlew.bat", + "!android/local.properties", + "!**/__tests__", + "!**/__fixtures__", + "!**/__mocks__", + "!**/.*" + ], + "scripts": { + "pretest": "npm run prebuild", + "test": "jest -c jest.config.js", + "prepublishOnly": "cd .. && yarn build", + "prebuild": "node -p \"'export const version = ' + JSON.stringify(require('./package.json').version)\" > src/version.ts", + "build": "rm -rf lib && tsc --outDir ./lib && babel ./lib --out-dir lib --extensions '.js'" + }, + "repository": { + "type": "git", + "url": "https://github.com/PostHog/posthog-js-lite.git", + "directory": "react-native-session-replay" + }, + "devDependencies": { + "@types/jest": "^28.1.5", + "@types/react": "^18.2.44", + "eslint": "^8.19.0", + "eslint-config-prettier": "^8.5.0", + "eslint-plugin-prettier": "^4.2.1", + "jest": "^29.0.0", + "prettier": "^2.7.1", + "react": "^18.2.0", + "react-native": "^0.69.1", + "turbo": "^1.10.7", + "typescript": "^4.7.4" + }, + "peerDependencies": { + "react-native": "*" + } +} diff --git a/test/posthog-react-native-session-replay/posthog-react-native-session-replay.podspec b/test/posthog-react-native-session-replay/posthog-react-native-session-replay.podspec new file mode 100644 index 00000000..4b687117 --- /dev/null +++ b/test/posthog-react-native-session-replay/posthog-react-native-session-replay.podspec @@ -0,0 +1,41 @@ +require "json" + +package = JSON.parse(File.read(File.join(__dir__, "package.json"))) +folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' + +Pod::Spec.new do |s| + s.name = "posthog-react-native-session-replay" + s.version = package["version"] + s.summary = package["description"] + s.homepage = package["homepage"] + s.license = package["license"] + s.authors = package["author"] + + s.platforms = { :ios => min_ios_version_supported } + s.source = { :git => "https://github.com/marandaneto/posthog-react-native-session-replay.git", :tag => "#{s.version}" } + + s.source_files = "ios/**/*.{h,m,mm,swift}" + + # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0. + # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79. + if respond_to?(:install_modules_dependencies, true) + install_modules_dependencies(s) + else + s.dependency "React-Core" + + # Don't install the dependencies when we run `pod install` in the old architecture. + if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then + s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1" + s.pod_target_xcconfig = { + "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", + "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1", + "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" + } + s.dependency "React-Codegen" + s.dependency "RCT-Folly" + s.dependency "RCTRequired" + s.dependency "RCTTypeSafety" + s.dependency "ReactCommon/turbomodule/core" + end + end +end diff --git a/test/posthog-react-native-session-replay/src/index.tsx b/test/posthog-react-native-session-replay/src/index.tsx new file mode 100644 index 00000000..d452add2 --- /dev/null +++ b/test/posthog-react-native-session-replay/src/index.tsx @@ -0,0 +1,22 @@ +import { NativeModules, Platform } from 'react-native'; + +const LINKING_ERROR = + `The package 'posthog-react-native-session-replay' doesn't seem to be linked. Make sure: \n\n` + + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + + '- You rebuilt the app after installing the package\n' + + '- You are not using Expo Go\n'; + +const PosthogReactNativeSessionReplay = NativeModules.PosthogReactNativeSessionReplay + ? NativeModules.PosthogReactNativeSessionReplay + : new Proxy( + {}, + { + get() { + throw new Error(LINKING_ERROR); + }, + } + ); + +export function multiply(a: number, b: number): Promise { + return PosthogReactNativeSessionReplay.multiply(a, b); +} diff --git a/test/posthog-react-native-session-replay/src/version.ts b/test/posthog-react-native-session-replay/src/version.ts new file mode 100644 index 00000000..5b7415af --- /dev/null +++ b/test/posthog-react-native-session-replay/src/version.ts @@ -0,0 +1 @@ +export const version = "0.1.0" diff --git a/test/posthog-react-native-session-replay/tsconfig.json b/test/posthog-react-native-session-replay/tsconfig.json new file mode 100644 index 00000000..643a1dc6 --- /dev/null +++ b/test/posthog-react-native-session-replay/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "declaration": true, + "esModuleInterop": true, + "jsx": "react-native", + "lib": ["ESNext"], + "module": "ESNext", + "moduleResolution": "Node", + "noEmitOnError": true, + "outDir": "./lib", + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "target": "ES2018" + }, + "include": ["index.ts", "src/**/*.ts", "src/**/*.tsx"] +} diff --git a/test/posthog-react-native-session-replay/turbo.json b/test/posthog-react-native-session-replay/turbo.json new file mode 100644 index 00000000..2e2e634a --- /dev/null +++ b/test/posthog-react-native-session-replay/turbo.json @@ -0,0 +1,27 @@ +{ + "$schema": "https://turbo.build/schema.json", + "pipeline": { + "build:android": { + "env": ["ORG_GRADLE_PROJECT_newArchEnabled"], + "inputs": [ + "package.json", + "android", + "!android/build", + "src/*.ts", + "src/*.tsx" + ], + "outputs": [] + }, + "build:ios": { + "env": ["RCT_NEW_ARCH_ENABLED"], + "inputs": [ + "package.json", + "*.podspec", + "ios", + "src/*.ts", + "src/*.tsx" + ], + "outputs": [] + } + } +}