Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoF09 committed Feb 17, 2021
1 parent c85a724 commit 14f1859
Show file tree
Hide file tree
Showing 29 changed files with 332 additions and 1,114 deletions.
24 changes: 24 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"files": [
"README.md"
],
"imageSize": 100,
"commit": false,
"contributors": [
{
"login": "Marcoo09",
"name": "Marco Fiorito",
"avatar_url": "https://avatars.githubusercontent.com/Marcoo09",
"profile": "https://github.com/Marcoo09",
"contributions": [
"code",
]
},
],
"contributorsPerLine": 7,
"projectName": "react-native-vimeo-player",
"projectOwner": "Marcoo09",
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Alex Demchenko
Copyright (c) 2021 Marco Fiorito

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
157 changes: 37 additions & 120 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,138 +1,55 @@
# React Native Module Template
# React Native Vimeo Player

A starter for the React Native library written in TypeScript, with linked example project and optional native code written in Swift and Kotlin. This project aims to support the latest React Native versions and keep best practices in mind.
React Native Vimeo Player is a library to render Vimeo videos in a React Native app.
This component allows you to embed a Vimeo video in your app and have full access to
the Vimeo player JS API (more information https://developer.vimeo.com/player/js-api).

## Alternatives
## Installation

[create-react-native-module](https://github.com/brodybits/create-react-native-module)
1. Go through the instructions for installing the
`React Native Webview` library: https://github.com/react-native-webview/react-native-webview.

### Why this template?
1. Run `npm install react-native-vimeo-player` or `yarn add react-native-vimeo-player` within your project.

First of all, it has TypeScript set up and ready. Also, if you will use a native code, this template uses Swift and Kotlin, which is much better than Objective-C and Java.

The example project is linked in a way so that you can work on your library and see the results of your work immediately. If you use native code you can see linked libraries in the example project opened in Xcode or Android Studio and can modify the code directly from there, just remember to rebuild the example to see the changes. When you change TypeScript code you need to compile it first (using `yarn` command, it has `prepare` hook set up) since with npm you are supplying `lib` folder with JavaScript and type definitions, but there is an [option](#how-to-see-my-changes-immediately-in-the-example) to point example to the `src` folder instead, so that when you modify your library you see changes immediately in the example thanks to [Fast Refresh](https://facebook.github.io/react-native/docs/fast-refresh).
1. Compile and build to make sure everything is set up properly.

## Usage

Clone this repo, rename the `react-native-module-template` folder to your library name, navigate to that folder and run

```
node rename.js
```

or if you want to **remove native code**

```
node rename.js js-only
```

This will invoke rename script, which removes all references to the template and makes some cleanup.

⚠️⚠️⚠️ This script is not made to be bulletproof, some assumptions are made:

- The script will ask for different information (such as library name, author name, author email etc.) and there might be instructions in the parenthesis, please follow them or something will likely **fail**.
- Use `kebab-case` for the library name, _preferably_ with `react-native` prefix (e.g. `react-native-blue-button`, blue-button, button).
- Use `PascalCase` for the library short name (in case you will have native code, with `js-only` argument script will not ask for this), it is used in native projects (RNModuleTemplate.xcodeproj, RNModuleTemplatePackage.kt etc.). If you prefixed your library name with `react-native` use prefix `RN` for the short name (e.g. `RNBlueButton`, BlueButton, Button).
- Library homepage is used only in `package.json`, if you are not sure, you can press enter to skip this step and modify this field later. Library git url is used only in `.podspec` file, same as above (note that this file will be removed if you pass `js-only` argument).
- Please don't use any special characters in author name since it is a part of Android package name, (e.g. `com.alexdemchenko.reactnativemoduletemplate`) and used in Kotlin and other files. Android package name is generated from author name (with removed spaces and lowercased) and library name (with removed dashes).

Don't forget to remove the rename script, do `yarn` to install dependencies in root and example folders, and, if you kept native code, do `pod install` in `example/ios`.

If you didn't use `js-only` you are good to go. If you did, you need to unlink native code from the example

### iOS

Open Xcode, in the project navigator find `Libraries` folder, reveal contents using the small arrow and hit `DELETE` on `RNModuleTemplate.xcodeproj`. Alternatively, open `example/ios/example.xcodeproj/project.pbxproj`, search for the `Template` (there should be a number of `libRNModuleTemplate.a` and `RNModuleTemplate.xcodeproj` files) and remove all references to them. Please remove whole lines if it among files with other names or whole sections if it is the only item. Groups, like `Library` or `Products`, must stay, just remove the template from appropriate children field.

### Android

In `example/android/settings.gradle` remove

```gradle
include ':react-native-module-template'
project(':react-native-module-template').projectDir = new File(rootProject.projectDir, '../../android')
```

In `example/android/app/build.gradle` remove

```gradle
implementation project(':react-native-module-template')
```

In `example/android/app/src/main/java/com/example/MainApplication.kt` remove

```kotlin
import com.alexdemchenko.reactnativemoduletemplate.RNModuleTemplatePackage

packages.add(RNModuleTemplatePackage())
```

## How example project is linked

The native part is manually linked (you can see changes for Android right above), for iOS check [official docs](https://facebook.github.io/react-native/docs/linking-libraries-ios#manual-linking), but **Header Search Paths** are pointing to the `ios` folder, `$(SRCROOT)/../../ios`, not node_modules.

JavaScript part is using Metro Bundler configuration, see [this article](https://callstack.com/blog/adding-an-example-app-to-your-react-native-library/) for more details and final configuration [here](example/metro.config.js).

In the example's [tsconfig.json](example/tsconfig.json) custom path is specified, so you can import your code the same way end user will do.

```json
"paths": {
"react-native-module-template": ["../src"]
},
```

### How to see my changes immediately in the example

In the library's `package.json` change

```json
"main": "lib/index.js",
```

to

```json
"main": "src/index.tsx", // or `index.ts` if you don't have JSX there
```

restart the bundler if you have it running

```
yarn start
<Vimeo
videoId={'513199601'}
onReady={() => console.log('Video is ready')}
onPlay={() => console.log('Video is playing')}
onPlayProgress={(data) => console.log('Video progress data:', data)}
onFinish={() => console.log('Video is finished')}
loop={false}
autoPlay={false}
controls={true}
speed={false}
/>
```

⚠️⚠️⚠️ Don't forget to change this back before making a release, since with npm you supply `lib` folder, not `src`. Let me know if there is a way to do this automatically.
## How it works

## Release
Internally, a webview loads a HTML page. This HTML page loads your
Vimeo video in an iFrame, then uses the Froogaloop JS library provided by Vimeo to pass event
information to your application.

Create an npm account [here](https://www.npmjs.com/signup) if you don't have one. Then do
## Example

```
npm login
```
If you want to see `MetaLabs-inc/react-native-vimeo-player` in action, just move into the [example](/example) folder and run `yarn && cd ios && pod install && cd .. && yarn ios` or `yarn && yarn android`. By seeing its source code, you will have a better understanding of the library usage.

and

```
npm publish
```
## Contributors

ℹ️ If you want to see what files will be included in your package before release run `npm pack`

ℹ️ If you have native code in your library most of the time you will need `.kt`, `.h`/`.m`, `.swift` files, `project.pbxproj`, `AndroidManifest.xml` and `build.gradle` aside from TypeScript code and default stuff, so keep an eye on what you are publishing, some configuration/build folders or files might sneak in. Most of them (if not all) are ignored in [package.json](package.json).

## FAQ

### VSCode ESLint plugin does not lint example project

By default, ESLint is configured separately for the library's source code and the example. It uses two `.eslintignore` files, the first one for the library, among others it ignores `/example` folder, and the second one for the example project. Since `/example` folder is ignored in one of these files, the plugin does not lint anything in it, see this [issue](https://github.com/microsoft/vscode-eslint/issues/111). To fix that, go to the VSCode settings and set

```json
"eslint.workingDirectories": [
"./example"
]
```
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://github.com/Marcoo09"><img src="https://avatars.githubusercontent.com/Marcoo09" width="100px;" alt=""/><br /><sub><b>Marco Fiorito</b></sub></a><br />💻</td>
</tr>
</table>

## License
## Acknowledgements

[MIT](LICENSE)
- [@Myagi](https://github.com/Myagi) for `react-native-vimeo`, I based on that library to make that library with the latest versions of react-native.
44 changes: 0 additions & 44 deletions android/build.gradle

This file was deleted.

2 changes: 0 additions & 2 deletions android/src/main/AndroidManifest.xml

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ android {
}

dependencies {
implementation project(':react-native-module-template')
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.example

import android.app.Application
import android.content.Context
import com.alexdemchenko.reactnativemoduletemplate.RNModuleTemplatePackage
import com.facebook.react.*
import com.facebook.soloader.SoLoader
import java.lang.reflect.InvocationTargetException
Expand All @@ -16,7 +15,6 @@ class MainApplication : Application(), ReactApplication {

override fun getPackages(): List<ReactPackage> {
val packages = PackageList(this).packages
packages.add(RNModuleTemplatePackage())
return packages
}

Expand Down
3 changes: 0 additions & 3 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
rootProject.name = 'example'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

include ':react-native-module-template'
project(':react-native-module-template').projectDir = new File(rootProject.projectDir, '../../android')

Expand Down
8 changes: 7 additions & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ PODS:
- React-cxxreact (= 0.63.4)
- React-jsi (= 0.63.4)
- React-jsinspector (0.63.4)
- react-native-webview (11.2.3):
- React-Core
- React-RCTActionSheet (0.63.4):
- React-Core/RCTActionSheetHeaders (= 0.63.4)
- React-RCTAnimation (0.63.4):
Expand Down Expand Up @@ -337,6 +339,7 @@ DEPENDENCIES:
- React-jsi (from `../node_modules/react-native/ReactCommon/jsi`)
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- react-native-webview (from `../node_modules/react-native-webview`)
- React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`)
- React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`)
- React-RCTBlob (from `../node_modules/react-native/Libraries/Blob`)
Expand Down Expand Up @@ -395,6 +398,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsiexecutor"
React-jsinspector:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
react-native-webview:
:path: "../node_modules/react-native-webview"
React-RCTActionSheet:
:path: "../node_modules/react-native/Libraries/ActionSheetIOS"
React-RCTAnimation:
Expand Down Expand Up @@ -445,6 +450,7 @@ SPEC CHECKSUMS:
React-jsi: a0418934cf48f25b485631deb27c64dc40fb4c31
React-jsiexecutor: 93bd528844ad21dc07aab1c67cb10abae6df6949
React-jsinspector: 58aef7155bc9a9683f5b60b35eccea8722a4f53a
react-native-webview: 6520e3e7b4933de76b95ef542c8d7115cf45b68e
React-RCTActionSheet: 89a0ca9f4a06c1f93c26067af074ccdce0f40336
React-RCTAnimation: 1bde3ecc0c104c55df246eda516e0deb03c4e49b
React-RCTBlob: a97d378b527740cc667e03ebfa183a75231ab0f0
Expand All @@ -460,4 +466,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 67546a31292453d5d7519f46729a35755310976e

COCOAPODS: 1.10.1
COCOAPODS: 1.9.3
Loading

0 comments on commit 14f1859

Please sign in to comment.