Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Sep 16, 2024
1 parent 752237c commit 070db1e
Show file tree
Hide file tree
Showing 26 changed files with 356 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Mon Sep 16 11:59:46 BST 2024
gradle.version=8.9
Empty file.
99 changes: 99 additions & 0 deletions test/posthog-react-native-session-replay/android/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PosthogReactNativeSessionReplay_kotlinVersion=1.7.0
PosthogReactNativeSessionReplay_minSdkVersion=21
PosthogReactNativeSessionReplay_targetSdkVersion=31
PosthogReactNativeSessionReplay_compileSdkVersion=31
PosthogReactNativeSessionReplay_ndkversion=21.4.7075529
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.posthogreactnativesessionreplay">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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<NativeModule> {
return listOf(PosthogReactNativeSessionReplayModule(reactContext))
}

override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
return emptyList()
}
}
3 changes: 3 additions & 0 deletions test/posthog-react-native-session-replay/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset', '@babel/env', '@babel/preset-typescript'],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import <React/RCTBridgeModule.h>

@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
Original file line number Diff line number Diff line change
@@ -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)
}
}
16 changes: 16 additions & 0 deletions test/posthog-react-native-session-replay/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
preset: 'jest-expo',
roots: ['<rootDir>'],
testEnvironment: 'node',
transform: {
'^.+\\.ts$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'json', 'node', 'tsx'],
collectCoverage: true,
clearMocks: true,
coverageDirectory: 'coverage',
testPathIgnorePatterns: ['<rootDir>/lib/', 'node_modules', 'examples'],
fakeTimers: { enableGlobally: true },
transformIgnorePatterns: [],
}

51 changes: 51 additions & 0 deletions test/posthog-react-native-session-replay/package.json
Original file line number Diff line number Diff line change
@@ -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": "*"
}
}
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions test/posthog-react-native-session-replay/src/index.tsx
Original file line number Diff line number Diff line change
@@ -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<number> {
return PosthogReactNativeSessionReplay.multiply(a, b);
}
1 change: 1 addition & 0 deletions test/posthog-react-native-session-replay/src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const version = "0.1.0"
18 changes: 18 additions & 0 deletions test/posthog-react-native-session-replay/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}
27 changes: 27 additions & 0 deletions test/posthog-react-native-session-replay/turbo.json
Original file line number Diff line number Diff line change
@@ -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": []
}
}
}

0 comments on commit 070db1e

Please sign in to comment.