Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Trocki committed Sep 13, 2022
1 parent 3517160 commit fcbc131
Show file tree
Hide file tree
Showing 141 changed files with 9,780 additions and 15,649 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ lib/

#e2e
test-butler-app.apk
example/vendor
19 changes: 15 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ To get started with the project, run `yarn` in the root directory to install the
yarn
```

While developing, you can run the [example app](/example/) to test your changes.
> While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development.
While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app.

To start the packager:

Expand All @@ -30,6 +32,7 @@ To run the example app on iOS:
yarn example ios
```


Make sure your code passes TypeScript and ESLint. Run the following to verify:

```sh
Expand All @@ -48,11 +51,9 @@ Remember to add tests for your change if possible. Run the unit tests by:
```sh
yarn test
```

To edit the Objective-C files, open `example/ios/PagerViewExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-pager-view`.

To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativepagerview` under `Android`.

### Commit message convention

We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
Expand All @@ -74,6 +75,16 @@ We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint]

Our pre-commit hooks verify that the linter and tests pass when committing.

### Publishing to npm

We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc.

To publish new versions, run the following:

```sh
yarn release
```

### Scripts

The `package.json` file contains various scripts for common tasks:
Expand All @@ -88,7 +99,7 @@ The `package.json` file contains various scripts for common tasks:

### Sending a pull request

> **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github).
> **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).
When you're sending a pull request:

Expand Down
70 changes: 43 additions & 27 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
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['PagerView_kotlinVersion']

repositories {
google()
jcenter()
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:3.5.3'
}
}

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['PagerView_' + name]
Expand All @@ -27,31 +29,39 @@ def getExtOrIntegerDefault(name) {

android {
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')

defaultConfig {
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
versionCode 1
versionName "1.0"

buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}

buildTypes {
release {
minifyEnabled false
}
}

lintOptions {
disable 'GradleCompatible'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += ['src/turbo']
} else {
java.srcDirs += ['src/legacy']
}
}
}
}

repositories {
mavenCentral()
jcenter()
google()

def found = false
Expand All @@ -62,8 +72,8 @@ repositories {
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
} else {
defaultDir = new File(
projectDir,
'/../../../node_modules/react-native/android'
projectDir,
'/../../../node_modules/react-native/android'
)
}

Expand All @@ -83,13 +93,13 @@ repositories {
parentDir = parentDir.parentFile

def androidSourcesDir = new File(
parentDir,
'node_modules/react-native'
parentDir,
'node_modules/react-native'
)

def androidPrebuiltBinaryDir = new File(
parentDir,
'node_modules/react-native/android'
parentDir,
'node_modules/react-native/android'
)

if (androidPrebuiltBinaryDir.exists()) {
Expand All @@ -114,17 +124,23 @@ repositories {

if (!found) {
throw new GradleException(
"${project.name}: unable to locate React Native android sources. " +
"Ensure you have you installed React Native as a dependency in your project and try again."
"${project.name}: unable to locate React Native android sources. " +
"Ensure you have you installed React Native as a dependency in your project and try again."
)
}
}

def kotlin_version = getExtOrDefault('kotlinVersion')

dependencies {
// noinspection GradleDynamicVersion
api 'com.facebook.react:react-native:+'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.viewpager2:viewpager2:1.0.0'
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
// From node_modules
}

if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../src/")
libraryName = "PagerViewView"
codegenJavaPackageName = "com.reactnativepagerview"
}
}
8 changes: 4 additions & 4 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PagerView_kotlinVersion=1.5.30
PagerView_compileSdkVersion=30
PagerView_buildToolsVersion=30.0.2
PagerView_targetSdkVersion=30
PagerView_kotlinVersion=1.7.0
PagerView_minSdkVersion=21
PagerView_targetSdkVersion=31
PagerView_compileSdkVersion=31
PagerView_ndkversion=21.4.7075529
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.reactnativepagerview;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.bridge.ReactApplicationContext;

import java.util.Map;


public class PagerViewViewManager extends SimpleViewManager<PagerViewView> {

ReactApplicationContext mCallerContext;

public PagerViewViewManager(ReactApplicationContext reactContext) {
mCallerContext = reactContext;
}

@Override
public String getName() {
return PagerViewViewManagerImpl.NAME;
}

@Override
public PagerViewView createViewInstance(ThemedReactContext context) {
return PagerViewViewManagerImpl.createViewInstance(context);
}

@Override
public Map<String, Integer> getCommandsMap() {
return MapBuilder.of("changeBackgroundColor", 1);
}

@Override
public void receiveCommand(
@NonNull PagerViewView view,
String commandId,
@Nullable ReadableArray args
) {
super.receiveCommand(view, commandId, args);
String color = args.getString(0);

switch (commandId) {
case "changeBackgroundColor":
setColor(view, color);
break;
default: {}
}
}


@ReactProp(name = "color")
public void setColor(PagerViewView view, String color) {
PagerViewViewManagerImpl.setColor(view, color);
}
}
21 changes: 0 additions & 21 deletions android/src/main/java/com/reactnativepagerview/Helper.kt

This file was deleted.

This file was deleted.

Loading

0 comments on commit fcbc131

Please sign in to comment.