Skip to content

Commit fcbc131

Browse files
author
Piotr Trocki
committed
init project
1 parent 3517160 commit fcbc131

File tree

141 files changed

+9780
-15649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+9780
-15649
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ lib/
6161

6262
#e2e
6363
test-butler-app.apk
64+
example/vendor

CONTRIBUTING.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ To get started with the project, run `yarn` in the root directory to install the
1010
yarn
1111
```
1212

13-
While developing, you can run the [example app](/example/) to test your changes.
13+
> 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.
14+
15+
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.
1416

1517
To start the packager:
1618

@@ -30,6 +32,7 @@ To run the example app on iOS:
3032
yarn example ios
3133
```
3234

35+
3336
Make sure your code passes TypeScript and ESLint. Run the following to verify:
3437

3538
```sh
@@ -48,11 +51,9 @@ Remember to add tests for your change if possible. Run the unit tests by:
4851
```sh
4952
yarn test
5053
```
51-
5254
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`.
5355

5456
To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativepagerview` under `Android`.
55-
5657
### Commit message convention
5758

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

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

78+
### Publishing to npm
79+
80+
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.
81+
82+
To publish new versions, run the following:
83+
84+
```sh
85+
yarn release
86+
```
87+
7788
### Scripts
7889

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

89100
### Sending a pull request
90101

91-
> **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).
102+
> **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).
92103
93104
When you're sending a pull request:
94105

android/build.gradle

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
buildscript {
2-
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
3-
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['PagerView_kotlinVersion']
4-
52
repositories {
6-
google()
7-
jcenter()
3+
google()
4+
mavenCentral()
85
}
96

107
dependencies {
11-
classpath 'com.android.tools.build:gradle:4.2.1'
12-
// noinspection DifferentKotlinGradleVersion
13-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
8+
classpath 'com.android.tools.build:gradle:3.5.3'
149
}
1510
}
1611

12+
def isNewArchitectureEnabled() {
13+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
14+
}
15+
1716
apply plugin: 'com.android.library'
18-
apply plugin: 'kotlin-android'
17+
18+
if (isNewArchitectureEnabled()) {
19+
apply plugin: 'com.facebook.react'
20+
}
1921

2022
def getExtOrDefault(name) {
2123
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['PagerView_' + name]
@@ -27,31 +29,39 @@ def getExtOrIntegerDefault(name) {
2729

2830
android {
2931
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
32+
3033
defaultConfig {
3134
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
3235
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
33-
versionCode 1
34-
versionName "1.0"
35-
36+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
3637
}
37-
3838
buildTypes {
3939
release {
4040
minifyEnabled false
4141
}
4242
}
43+
4344
lintOptions {
4445
disable 'GradleCompatible'
4546
}
47+
4648
compileOptions {
4749
sourceCompatibility JavaVersion.VERSION_1_8
4850
targetCompatibility JavaVersion.VERSION_1_8
4951
}
52+
sourceSets {
53+
main {
54+
if (isNewArchitectureEnabled()) {
55+
java.srcDirs += ['src/turbo']
56+
} else {
57+
java.srcDirs += ['src/legacy']
58+
}
59+
}
60+
}
5061
}
5162

5263
repositories {
5364
mavenCentral()
54-
jcenter()
5565
google()
5666

5767
def found = false
@@ -62,8 +72,8 @@ repositories {
6272
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
6373
} else {
6474
defaultDir = new File(
65-
projectDir,
66-
'/../../../node_modules/react-native/android'
75+
projectDir,
76+
'/../../../node_modules/react-native/android'
6777
)
6878
}
6979

@@ -83,13 +93,13 @@ repositories {
8393
parentDir = parentDir.parentFile
8494

8595
def androidSourcesDir = new File(
86-
parentDir,
87-
'node_modules/react-native'
96+
parentDir,
97+
'node_modules/react-native'
8898
)
8999

90100
def androidPrebuiltBinaryDir = new File(
91-
parentDir,
92-
'node_modules/react-native/android'
101+
parentDir,
102+
'node_modules/react-native/android'
93103
)
94104

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

115125
if (!found) {
116126
throw new GradleException(
117-
"${project.name}: unable to locate React Native android sources. " +
118-
"Ensure you have you installed React Native as a dependency in your project and try again."
127+
"${project.name}: unable to locate React Native android sources. " +
128+
"Ensure you have you installed React Native as a dependency in your project and try again."
119129
)
120130
}
121131
}
122132

123-
def kotlin_version = getExtOrDefault('kotlinVersion')
124133

125134
dependencies {
126-
// noinspection GradleDynamicVersion
127-
api 'com.facebook.react:react-native:+'
128-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
129-
implementation 'androidx.viewpager2:viewpager2:1.0.0'
135+
//noinspection GradleDynamicVersion
136+
implementation "com.facebook.react:react-native:+"
137+
// From node_modules
138+
}
139+
140+
if (isNewArchitectureEnabled()) {
141+
react {
142+
jsRootDir = file("../src/")
143+
libraryName = "PagerViewView"
144+
codegenJavaPackageName = "com.reactnativepagerview"
145+
}
130146
}

android/gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
PagerView_kotlinVersion=1.5.30
2-
PagerView_compileSdkVersion=30
3-
PagerView_buildToolsVersion=30.0.2
4-
PagerView_targetSdkVersion=30
1+
PagerView_kotlinVersion=1.7.0
52
PagerView_minSdkVersion=21
3+
PagerView_targetSdkVersion=31
4+
PagerView_compileSdkVersion=31
5+
PagerView_ndkversion=21.4.7075529
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.reactnativepagerview;
2+
3+
import androidx.annotation.NonNull;
4+
import androidx.annotation.Nullable;
5+
6+
import com.facebook.react.bridge.ReadableArray;
7+
import com.facebook.react.common.MapBuilder;
8+
import com.facebook.react.uimanager.SimpleViewManager;
9+
import com.facebook.react.uimanager.ThemedReactContext;
10+
import com.facebook.react.uimanager.annotations.ReactProp;
11+
import com.facebook.react.bridge.ReactApplicationContext;
12+
13+
import java.util.Map;
14+
15+
16+
public class PagerViewViewManager extends SimpleViewManager<PagerViewView> {
17+
18+
ReactApplicationContext mCallerContext;
19+
20+
public PagerViewViewManager(ReactApplicationContext reactContext) {
21+
mCallerContext = reactContext;
22+
}
23+
24+
@Override
25+
public String getName() {
26+
return PagerViewViewManagerImpl.NAME;
27+
}
28+
29+
@Override
30+
public PagerViewView createViewInstance(ThemedReactContext context) {
31+
return PagerViewViewManagerImpl.createViewInstance(context);
32+
}
33+
34+
@Override
35+
public Map<String, Integer> getCommandsMap() {
36+
return MapBuilder.of("changeBackgroundColor", 1);
37+
}
38+
39+
@Override
40+
public void receiveCommand(
41+
@NonNull PagerViewView view,
42+
String commandId,
43+
@Nullable ReadableArray args
44+
) {
45+
super.receiveCommand(view, commandId, args);
46+
String color = args.getString(0);
47+
48+
switch (commandId) {
49+
case "changeBackgroundColor":
50+
setColor(view, color);
51+
break;
52+
default: {}
53+
}
54+
}
55+
56+
57+
@ReactProp(name = "color")
58+
public void setColor(PagerViewView view, String color) {
59+
PagerViewViewManagerImpl.setColor(view, color);
60+
}
61+
}

android/src/main/java/com/reactnativepagerview/Helper.kt

Lines changed: 0 additions & 21 deletions
This file was deleted.

android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)