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
37 changes: 8 additions & 29 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ This project is a monorepo managed using [Yarn workspaces](https://yarnpkg.com/f
- The library package in the root directory.
- An example app in the `example/` directory.

To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
To get started with the project, make sure you have the correct version of [Node.js](https://nodejs.org/) installed. See the [`.nvmrc`](./.nvmrc) file for the version used in this project.

Run `yarn` in the root directory to install the required dependencies for each package:

```sh
yarn
```

> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development.
> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development without manually migrating.

The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make.

It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app.

If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/ReactNativeSnapshotViewExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > @azzapp/react-native-snapshot-view`.
If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/SnapshotViewExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-snapshot-view`.

To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `azzapp-react-native-snapshot-view` under `Android`.
To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `react-native-snapshot-view` under `Android`.

You can use various commands from the root directory to work with the project.

Expand All @@ -47,33 +49,10 @@ To run the example app on iOS:
yarn example ios
```

By default, the example is configured to build with the old architecture. To run the example with the new architecture, you can do the following:

1. For Android, run:

```sh
ORG_GRADLE_PROJECT_newArchEnabled=true yarn example android
```

2. For iOS, run:

```sh
cd example/ios
RCT_NEW_ARCH_ENABLED=1 pod install
cd -
yarn example ios
```

If you are building for a different architecture than your previous build, make sure to remove the build folders first. You can run the following command to cleanup all build folders:

```sh
yarn clean
```

To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this:

```sh
Running "ReactNativeSnapshotViewExample" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1}
Running "SnapshotViewExample" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1}
```

Note the `"fabric":true` and `"concurrentRoot":true` properties.
Expand Down Expand Up @@ -104,7 +83,7 @@ We follow the [conventional commits specification](https://www.conventionalcommi
- `fix`: bug fixes, e.g. fix crash due to deprecated method.
- `feat`: new features, e.g. add new method to the module.
- `refactor`: code refactor, e.g. migrate from class components to hooks.
- `docs`: changes into documentation, e.g. add usage example for the module..
- `docs`: changes into documentation, e.g. add usage example for the module.
- `test`: adding or updating tests, e.g. add integration tests using detox.
- `chore`: tooling changes, e.g. change CI config.

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ const snapshotID = await captureSnapshot(viewRef.current);

>:warning: captured snapshot are kept in memory, either use `releaseSnapshot` to release them, or let the `SnapshotRenderer` component release the snapshot on unmount.


## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
- [Development workflow](CONTRIBUTING.md#development-workflow)
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
- [Code of conduct](CODE_OF_CONDUCT.md)

## License

Expand Down
72 changes: 13 additions & 59 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,70 +1,38 @@
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["ReactNativeSnapshotView_kotlinVersion"]
ext.getExtOrDefault = {name ->
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeSnapshotView_' + name]
}

repositories {
google()
mavenCentral()
}

dependencies {
classpath "com.android.tools.build:gradle:7.2.1"
classpath "com.android.tools.build:gradle:8.7.2"
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
}
}

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["ReactNativeSnapshotView_" + name]
}
apply plugin: "com.facebook.react"

def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ReactNativeSnapshotView_" + 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
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["SnapshotView_" + name]).toInteger()
}

android {
if (supportsNamespace()) {
namespace "com.azzapp.rnsnapshotview"

sourceSets {
main {
manifest.srcFile "src/main/AndroidManifestNew.xml"
}
}
}
namespace "com.azzapp.rnsnapshotview"

compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

defaultConfig {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

}

buildFeatures {
Expand All @@ -88,13 +56,10 @@ android {

sourceSets {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += [
"src/newarch",
]
} else {
java.srcDirs += ["src/oldarch"]
}
java.srcDirs += [
"generated/java",
"generated/jni"
]
}
}
}
Expand All @@ -107,17 +72,6 @@ repositories {
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 "com.facebook.react:react-android"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../src/")
libraryName = "ReactNativeSnapshotViewView"
codegenJavaPackageName = "com.azzapp.rnsnapshotview"
}
}
10 changes: 5 additions & 5 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ReactNativeSnapshotView_kotlinVersion=1.7.0
ReactNativeSnapshotView_minSdkVersion=21
ReactNativeSnapshotView_targetSdkVersion=31
ReactNativeSnapshotView_compileSdkVersion=31
ReactNativeSnapshotView_ndkversion=21.4.7075529
ReactNativeSnapshotView_kotlinVersion=2.0.21
ReactNativeSnapshotView_minSdkVersion=24
ReactNativeSnapshotView_targetSdkVersion=34
ReactNativeSnapshotView_compileSdkVersion=35
ReactNativeSnapshotView_ndkVersion=27.1.12297006
3 changes: 1 addition & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.azzapp.rnsnapshotview">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
2 changes: 0 additions & 2 deletions android/src/main/AndroidManifestNew.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
package com.azzapp.rnsnapshotview


import android.graphics.Color
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.viewmanagers.RNSnapshotRendererManagerInterface
import com.facebook.react.viewmanagers.RNSnapshotRendererManagerDelegate

@ReactModule(name = RNSnapshotRendererManager.NAME)
class RNSnapshotRendererManager :
RNSnapshotRendererManagerSpec<RNSnapshotRenderer>() {
class RNSnapshotRendererManager : SimpleViewManager<RNSnapshotRenderer>(),
RNSnapshotRendererManagerInterface<RNSnapshotRenderer> {
private val mDelegate: ViewManagerDelegate<RNSnapshotRenderer>
init {
mDelegate = RNSnapshotRendererManagerDelegate(this)
}

override fun getDelegate(): ViewManagerDelegate<RNSnapshotRenderer>? {
return mDelegate
}

override fun getName(): String {
return NAME
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.common.annotations.UnstableReactNativeAPI
import com.facebook.react.fabric.FabricUIManager
import com.facebook.react.uimanager.NativeViewHierarchyManager
import com.facebook.react.uimanager.UIBlock
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.uimanager.UIManagerModule
import com.facebook.react.uimanager.common.UIManagerType
import java.util.Collections
import java.util.LinkedList
Expand All @@ -32,7 +29,7 @@ import java.util.concurrent.TimeUnit


class ReactNativeSnapshotViewModule internal constructor(context: ReactApplicationContext) :
RNSnapshotViewSpec(context) {
NativeRNSnapshotViewSpec(context) {

override fun getName(): String {
return NAME
Expand All @@ -59,29 +56,15 @@ class ReactNativeSnapshotViewModule internal constructor(context: ReactApplicati
}
}

if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
val uiManager = UIManagerHelper.getUIManager(reactApplicationContext, UIManagerType.FABRIC)
if (uiManager is FabricUIManager) {
uiManager.addUIBlock { uiBlockViewResolver ->
val view = uiBlockViewResolver.resolveView(viewTag.toInt())
handleView(view);
}
} else {
promise.reject("not_found", "Cannot obtain UIManager")
return
}
} else {
val uiManager = reactApplicationContext.getNativeModule(
UIManagerModule::class.java
)
if (uiManager == null) {
promise.reject("not_found", "Cannot obtain UIManager")
return
}
uiManager.addUIBlock(UIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
val view = nativeViewHierarchyManager.resolveView(viewTag.toInt())
handleView(view)
})
val uiManager = UIManagerHelper.getUIManager(reactApplicationContext, UIManagerType.FABRIC)
if (uiManager !is FabricUIManager) {
promise.reject("not_found", "Cannot obtain UIManager")
return
}

uiManager.addUIBlock { uiBlockViewResolver ->
val view = uiBlockViewResolver.resolveView(viewTag.toInt())
handleView(view)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.module.model.ReactModuleInfo
import com.facebook.react.module.model.ReactModuleInfoProvider
import com.facebook.react.uimanager.ViewManager
import java.util.ArrayList
import java.util.HashMap

class ReactNativeSnapshotViewPackage : TurboReactPackage() {
Expand All @@ -21,22 +20,19 @@ class ReactNativeSnapshotViewPackage : TurboReactPackage() {
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
return ReactModuleInfoProvider {
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
moduleInfos[ReactNativeSnapshotViewModule.NAME] = ReactModuleInfo(
ReactNativeSnapshotViewModule.NAME,
ReactNativeSnapshotViewModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
true // isTurboModule
)
moduleInfos
}
}
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
val viewManagers: MutableList<ViewManager<*, *>> = ArrayList()
viewManagers.add(RNSnapshotRendererManager())
return viewManagers
return listOf(RNSnapshotRendererManager())
}
}
21 changes: 0 additions & 21 deletions android/src/newarch/RNSnapshotRendererManagerSpec.kt

This file was deleted.

7 changes: 0 additions & 7 deletions android/src/newarch/RNSnapshotViewSpec.kt

This file was deleted.

9 changes: 0 additions & 9 deletions android/src/oldarch/RNSnapshotRendererManagerSpec.kt

This file was deleted.

12 changes: 0 additions & 12 deletions android/src/oldarch/RNSnapshotViewSpec.kt

This file was deleted.

Loading
Loading