npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-native-form

v1.0.0

Published

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.

Downloads

1

Readme

React Native Module Template

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.

Alternatives

create-react-native-module

Why this template?

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 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.

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.java 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 Java 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

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

In example/android/app/build.gradle remove

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

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

import com.alexdemchenko.reactnativemoduletemplate.RNModuleTemplatePackage;

packages.add(new 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, 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 for more details and final configuration here.

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

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

How to see my changes immediately in the example

In the library's package.json change

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

to

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

restart the bundler if you have it running

yarn start

⚠️⚠️⚠️ 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.

Release

Create an npm account here if you don't have one. Then do

npm login

and

npm publish

ℹ️ 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 .java, .h/.m 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.

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. To fix that, go to the VSCode settings and set

"eslint.workingDirectories": [
	"./example"
]

License

MIT