Skip to content

Commit a2adf52

Browse files
Merge branch 'feature/cli' into 'main'
feature/cli See merge request react-native/react-native-material-components!12
2 parents 25cdba0 + d5c87a3 commit a2adf52

File tree

94 files changed

+19934
-18619
lines changed

Some content is hidden

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

94 files changed

+19934
-18619
lines changed

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Contributor Covenant Code of Conduct
23

34
## Our Pledge

CONTRIBUTING.md

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,15 @@ We want this community to be friendly and respectful to each other. Please follo
66

77
## Development workflow
88

9-
This project is a monorepo managed using [Yarn workspaces](https://yarnpkg.com/features/workspaces). It contains the following packages:
10-
11-
- The library package in the root directory.
12-
- An example app in the `example/` directory.
13-
149
To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
1510

1611
```sh
1712
yarn
1813
```
1914

20-
> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development.
21-
22-
The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make.
15+
> 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.
2316
24-
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.
25-
26-
You can use various commands from the root directory to work with the project.
17+
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.
2718

2819
To start the packager:
2920

@@ -43,12 +34,6 @@ To run the example app on iOS:
4334
yarn example ios
4435
```
4536

46-
To run the example app on Web:
47-
48-
```sh
49-
yarn example web
50-
```
51-
5237
Make sure your code passes TypeScript and ESLint. Run the following to verify:
5338

5439
```sh
@@ -68,6 +53,11 @@ Remember to add tests for your change if possible. Run the unit tests by:
6853
yarn test
6954
```
7055

56+
To edit the Objective-C or Swift files, open `example/ios/ReactNativeMaterialComponentsExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > @computools/react-native-material-components`.
57+
58+
To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `computools-react-native-material-components` under `Android`.
59+
60+
7161
### Commit message convention
7262

7363
We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
@@ -103,7 +93,7 @@ yarn release
10393

10494
The `package.json` file contains various scripts for common tasks:
10595

106-
- `yarn`: setup project by installing dependencies.
96+
- `yarn bootstrap`: setup project by installing all dependencies and pods.
10797
- `yarn typecheck`: type-check files with TypeScript.
10898
- `yarn lint`: lint files with ESLint.
10999
- `yarn test`: run unit tests with Jest.

README.md

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,35 @@ Computools react native material components package
66

77
1. ```yarn add @computools/react-native-material-components```
88

9-
2. ```yarn add react-native-reanimated```
9+
2. Add required dependency packages
10+
```
11+
yarn add react-native-reanimated
12+
yarn add react-native-gesture-handler
13+
yarn add react-native-safe-area-context
14+
```
1015

1116
3. Add ```react-native-reanimated/plugin``` plugin to your babel.config.js.
1217

1318
_react-native-reanimated/plugin has to be listed last._
1419

1520
See the [documentation](https://docs.swmansion.com/react-native-reanimated/) to learn more info about react-native-reanimated
1621

22+
4. Wrap whole App in ```SafeAreaProvider``` and ```GestureHandlerRootView``` containers.
23+
24+
See the example:
25+
26+
```
27+
export default function App() {
28+
return (
29+
<SafeAreaProvider>
30+
<GestureHandlerRootView style={{flex: 1}}>
31+
{/* Rest of your app code */}
32+
</GestureHandlerRootView>
33+
</SafeAreaProvider>
34+
);
35+
}
36+
```
37+
1738
# Platform specific setup
1839

1940
- Android
@@ -323,7 +344,102 @@ Outlined card is touchable.
323344

324345
![divider](https://ik.imagekit.io/Computools/rn-material-components/divider.png?updatedAt=1705067870577)
325346
</details>
347+
<details><summary>Sheets</summary>
348+
<br />
349+
<details><summary>Bottom Sheet</summary>
350+
351+
**Properties**
352+
353+
| name | description | type | default |
354+
| ------ | ------ | ------ | ---- |
355+
| header | | ReactNode | - |
356+
| children | - | ReactNode | - |
357+
| modalHeightCoeff | - | number | 0.4 |
358+
| animationDuration | - | number | 300 |
359+
| headerStyle | - | ViewStyle | - |
360+
| overlayStyle | - | ViewStyle | - |
361+
| dragHandleStyle | - | ViewStyle | - |
362+
363+
### Usage
364+
365+
1. Create a ref for a bottom sheet of the BottomSheetRef interface.
366+
2. Pass the bottom sheet ref as ref prop to ```BottomSheet```.
367+
3. Call ```toggle()``` method from ```ref.current``` to open/close the Bottom Sheet or ```expand()``` to expand the Bottom Sheet completely.
368+
369+
See the example:
370+
371+
```
372+
import {BottomSheet, type BottomSheetRef} from '@computools/react-native-material-components';
373+
374+
export const MyScreen = () => {
375+
const bottomSheetRef = React.useRef<BottomSheetRef>(null);
376+
377+
const toggleBottomSheet = () => ref.current?.toggle();
378+
379+
return (
380+
<>
381+
<View style={styles.container}>
382+
<Text onPress={toggleBottomSheet}>TOGGLE BOTTOM SHEET</Text>
383+
</View>
384+
<BottomSheet ref={ref}>
385+
{/* Bottom sheet content here */}
386+
</BottomSheet>
387+
</>
388+
);
389+
}
390+
```
391+
392+
**Note:** If you want to use scrollable components as children of Bottom Sheet you need to import them from react-native-gesture-handler. Otherwise they won't scroll on Android.
393+
394+
![left side sheet](https://ik.imagekit.io/Computools/rn-material-components/left-side-sheet.gif?updatedAt=1706170982231)
395+
</details>
396+
<details><summary>Side Sheet</summary>
397+
398+
**Properties**
399+
400+
| name | description | type | default |
401+
| ------ | ------ | ------ | ---- |
402+
| children | - | ReactNode | - |
403+
| stickySide | - | 'right' or 'left | 'right' |
404+
| modalWidthCoeff | up to 1 | number | 0.85 |
405+
| animationDuration | - | number | 300 |
406+
| overlayStyle | - | ViewStyle | - |
407+
408+
### Usage
409+
410+
1. Create a ref for a side sheet of the SideSheetRef interface.
411+
2. Pass the side sheet ref as ref prop to ```SideSheet```.
412+
3. Call ```toggle()``` method from ```ref.current``` to open/close the Side Sheet.
326413

414+
See the example:
415+
416+
```
417+
import {SideSheet, type SideSheetRef} from '@computools/react-native-material-components';
418+
419+
export const MyScreen = () => {
420+
const sideSheetRef = React.useRef<SideSheetRef>(null);
421+
422+
const toggleSideSheet = () => ref.current?.toggle();
423+
424+
return (
425+
<>
426+
<View style={styles.container}>
427+
<Text onPress={toggleSideSheet}>TOGGLE SIDE SHEET</Text>
428+
</View>
429+
<SideSheet ref={ref}>
430+
{/* Side sheet content here */}
431+
</SideSheet>
432+
</>
433+
);
434+
}
435+
```
436+
437+
**Note:** If you want to use scrollable components as children of Side Sheet you need to import them from react-native-gesture-handler. Otherwise they won't scroll on Android.
438+
439+
![left side sheet](https://ik.imagekit.io/Computools/rn-material-components/left-side-sheet.gif?updatedAt=1706170982231)
440+
![right side sheet](https://ik.imagekit.io/Computools/rn-material-components/right-side-sheet.gif?updatedAt=1706171192408)
441+
</details>
442+
</details>
327443
<details><summary>Snackbar</summary>
328444
<br />
329445

android/build.gradle

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
buildscript {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
}
6+
7+
dependencies {
8+
classpath "com.android.tools.build:gradle:7.2.1"
9+
}
10+
}
11+
12+
def isNewArchitectureEnabled() {
13+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
14+
}
15+
16+
apply plugin: "com.android.library"
17+
18+
19+
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
20+
21+
if (isNewArchitectureEnabled()) {
22+
apply plugin: "com.facebook.react"
23+
}
24+
25+
def getExtOrDefault(name) {
26+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["ReactNativeMaterialComponents_" + name]
27+
}
28+
29+
def getExtOrIntegerDefault(name) {
30+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ReactNativeMaterialComponents_" + name]).toInteger()
31+
}
32+
33+
def supportsNamespace() {
34+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
35+
def major = parsed[0].toInteger()
36+
def minor = parsed[1].toInteger()
37+
38+
// Namespace support was added in 7.3.0
39+
if (major == 7 && minor >= 3) {
40+
return true
41+
}
42+
43+
return major >= 8
44+
}
45+
46+
android {
47+
if (supportsNamespace()) {
48+
namespace "com.computools.reactnativematerialcomponents"
49+
50+
sourceSets {
51+
main {
52+
manifest.srcFile "src/main/AndroidManifestNew.xml"
53+
}
54+
}
55+
}
56+
57+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
58+
59+
defaultConfig {
60+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
61+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
62+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
63+
}
64+
buildTypes {
65+
release {
66+
minifyEnabled false
67+
}
68+
}
69+
70+
lintOptions {
71+
disable "GradleCompatible"
72+
}
73+
74+
compileOptions {
75+
sourceCompatibility JavaVersion.VERSION_1_8
76+
targetCompatibility JavaVersion.VERSION_1_8
77+
}
78+
79+
}
80+
81+
repositories {
82+
mavenCentral()
83+
google()
84+
}
85+
86+
87+
dependencies {
88+
// For < 0.71, this will be from the local maven repo
89+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
90+
//noinspection GradleDynamicVersion
91+
implementation "com.facebook.react:react-native:+"
92+
}
93+
94+
if (isNewArchitectureEnabled()) {
95+
react {
96+
jsRootDir = file("../src/")
97+
libraryName = "ReactNativeMaterialComponents"
98+
codegenJavaPackageName = "com.computools.reactnativematerialcomponents"
99+
}
100+
}

android/gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ReactNativeMaterialComponents_kotlinVersion=1.7.0
2+
ReactNativeMaterialComponents_minSdkVersion=21
3+
ReactNativeMaterialComponents_targetSdkVersion=31
4+
ReactNativeMaterialComponents_compileSdkVersion=31
5+
ReactNativeMaterialComponents_ndkversion=21.4.7075529
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.computools.reactnativematerialcomponents">
3+
</manifest>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
</manifest>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.computools.reactnativematerialcomponents;
2+
3+
import androidx.annotation.NonNull;
4+
5+
import com.facebook.react.bridge.Promise;
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
8+
import com.facebook.react.bridge.ReactMethod;
9+
import com.facebook.react.module.annotations.ReactModule;
10+
11+
@ReactModule(name = ReactNativeMaterialComponentsModule.NAME)
12+
public class ReactNativeMaterialComponentsModule extends ReactContextBaseJavaModule {
13+
public static final String NAME = "ReactNativeMaterialComponents";
14+
15+
public ReactNativeMaterialComponentsModule(ReactApplicationContext reactContext) {
16+
super(reactContext);
17+
}
18+
19+
@Override
20+
@NonNull
21+
public String getName() {
22+
return NAME;
23+
}
24+
25+
26+
// Example method
27+
// See https://reactnative.dev/docs/native-modules-android
28+
@ReactMethod
29+
public void multiply(double a, double b, Promise promise) {
30+
promise.resolve(a * b);
31+
}
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.computools.reactnativematerialcomponents;
2+
3+
import androidx.annotation.NonNull;
4+
5+
import com.facebook.react.ReactPackage;
6+
import com.facebook.react.bridge.NativeModule;
7+
import com.facebook.react.bridge.ReactApplicationContext;
8+
import com.facebook.react.uimanager.ViewManager;
9+
10+
import java.util.ArrayList;
11+
import java.util.Collections;
12+
import java.util.List;
13+
14+
public class ReactNativeMaterialComponentsPackage implements ReactPackage {
15+
@NonNull
16+
@Override
17+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
18+
List<NativeModule> modules = new ArrayList<>();
19+
modules.add(new ReactNativeMaterialComponentsModule(reactContext));
20+
return modules;
21+
}
22+
23+
@NonNull
24+
@Override
25+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
26+
return Collections.emptyList();
27+
}
28+
}

babel.config.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
module.exports = {
2-
presets: ['module:@react-native/babel-preset'],
3-
plugins: [
4-
[
5-
'module-resolver',
6-
{
7-
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
8-
},
9-
],
10-
'react-native-reanimated/plugin',
11-
],
2+
presets: ['module:metro-react-native-babel-preset'],
3+
plugins: ['react-native-reanimated/plugin'],
124
};

0 commit comments

Comments
 (0)