Skip to content

Commit

Permalink
feat(react-native): initialization (#1150)
Browse files Browse the repository at this point in the history
related with #1093 #1109 #1072 #1071

# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

I want to support isomorphic `<InView/>`, `<FadeIn/>` for react-dom and
react-native at once. This pull request is start for it

- @suspenisve/react-native 
- @suspenisve/react-dom

![Jul-27-2024
05-05-21-min](https://github.com/user-attachments/assets/ce5bc8bd-9a96-42b3-b954-672dacbc0dec)

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md)
2. I added documents and tests.
  • Loading branch information
manudeli authored Jul 30, 2024
1 parent 47ab7e6 commit b6e6920
Show file tree
Hide file tree
Showing 28 changed files with 8,434 additions and 367 deletions.
19 changes: 16 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ node_modules
coverage
__screenshots__
vitest.config.ts.timestamp*
tsconfig.vitest-temp.json

# next.js
.next/
Expand All @@ -20,6 +21,7 @@ build
# debug
npm-debug.log*
.pnpm-debug.log*
npm-debug.*

# local env files
.env.local
Expand All @@ -37,8 +39,19 @@ esm
# graph
graph/

# test
tsconfig.vitest-temp.json

# benchmark
benchmarks/

# react-native
expo-env.d.ts
.expo/
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/

# macOS
.DS_Store
10 changes: 10 additions & 0 deletions examples/react-native-playground/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
extends: ['@suspensive/eslint-config/react-ts', '@react-native-community'],
ignorePatterns: ['dist', 'coverage'],
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.json',
},
}
4 changes: 4 additions & 0 deletions examples/react-native-playground/.expo-shared/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true,
"40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true
}
28 changes: 28 additions & 0 deletions examples/react-native-playground/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { StyleSheet, Text, View } from 'react-native'
import { StatusBar } from 'expo-status-bar'
import { TestText } from '@suspensive/react-native'

export default function Native() {
return (
<View style={styles.container}>
<Text style={styles.header}>
Suspensive <TestText />
</Text>
<StatusBar style="auto" />
</View>
)
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
header: {
fontWeight: 'bold',
marginBottom: 20,
fontSize: 36,
},
})
3 changes: 3 additions & 0 deletions examples/react-native-playground/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Native

A [react-native](https://reactnative.dev/) app built using [expo](https://docs.expo.dev/)
31 changes: 31 additions & 0 deletions examples/react-native-playground/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"expo": {
"name": "react-native-playground",
"slug": "react-native-playground",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
}
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/react-native-playground/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/react-native-playground/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function (api) {
api.cache(true);
return {
presets: ["babel-preset-expo"],
};
};
8 changes: 8 additions & 0 deletions examples/react-native-playground/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { registerRootComponent } from "expo";

import App from "./App";

// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in Expo Go or in a native build,
// the environment is set up appropriately
registerRootComponent(App);
21 changes: 21 additions & 0 deletions examples/react-native-playground/metro.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require("expo/metro-config");
const path = require("path");

// Find the workspace root, this can be replaced with `find-yarn-workspace-root`
const workspaceRoot = path.resolve(__dirname, "../..");
const projectRoot = __dirname;

const config = getDefaultConfig(projectRoot);

// 1. Watch all files within the monorepo
config.watchFolders = [workspaceRoot];
// 2. Let Metro know where to resolve packages, and in what order
config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, "node_modules"),
path.resolve(workspaceRoot, "node_modules"),
];
// 3. Force Metro to resolve (sub)dependencies only from the `nodeModulesPaths`
config.resolver.disableHierarchicalLookup = true;

module.exports = config;
23 changes: 23 additions & 0 deletions examples/react-native-playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@suspensive/react-native-playground",
"version": "1.0.0",
"private": true,
"main": "index.js",
"scripts": {
"android": "expo start --android",
"eject": "expo eject",
"ios": "expo start --ios"
},
"dependencies": {
"@suspensive/react-native": "workspace:*",
"expo": "^51.0.22",
"expo-status-bar": "~1.12.1",
"react": "^18.3.1",
"react-native": "0.74.3"
},
"devDependencies": {
"@babel/core": "^7.24.9",
"@expo/webpack-config": "^19.0.1",
"@types/react": "^18.3.3"
}
}
7 changes: 7 additions & 0 deletions examples/react-native-playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "expo/tsconfig.base",
"include": [".", "./.eslintrc.cjs", "babel.config.js"],
"compilerOptions": {
"strict": true
}
}
4 changes: 4 additions & 0 deletions knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
},
"packages/react-query-*": {
"ignoreDependencies": ["@suspensive/react"]
},
"packages/react-native": {
"ignoreDependencies": ["expo", "@testing-library/react-native"],
"ignore": ["babel.config.cjs"]
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"ci:attw": "turbo run ci:attw",
"ci:bench": "turbo run ci:bench",
"ci:eslint": "turbo run ci:eslint",
"ci:knip": "pnpm prepack && pnpm knip",
"ci:publint": "turbo run ci:publint",
"ci:sherif": "sherif --ignore-package \"./examples/*\" --ignore-package \"./websites/*\" --ignore-package \"./docs/*\" --ignore-dependency \"@tanstack/react-query\" ",
"ci:test": "turbo run ci:test",
"ci:test:watch": "turbo run ci:test:watch --parallel",
"ci:type": "turbo run ci:type",
"ci:knip": "pnpm prepack && pnpm knip",
"clean": "turbo run clean",
"dev": "turbo run dev --concurrency 20",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
Expand Down
10 changes: 10 additions & 0 deletions packages/react-native/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
extends: ['@suspensive/eslint-config/react-ts'],
ignorePatterns: ['dist', 'coverage'],
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.json',
},
}
21 changes: 21 additions & 0 deletions packages/react-native/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Viva Republica, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions packages/react-native/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = (api) => {
api.cache(true)
return {
presets: ['babel-preset-expo'],
}
}
11 changes: 11 additions & 0 deletions packages/react-native/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { resolve } = require('path')

module.exports = {
preset: 'jest-expo',
transform: {
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',
},
// https://github.com/jestjs/jest/blob/b113b44e7252fef18c71d72e70a9293a50f50b96/examples/react-native/jest.config.js
transformIgnorePatterns: [resolve(__dirname, '../../packages')],
}
75 changes: 75 additions & 0 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"name": "@suspensive/react-native",
"version": "0.0.0",
"description": "Useful interfaces for React Suspense",
"keywords": [
"suspensive",
"react"
],
"homepage": "https://suspensive.org",
"bugs": "https://github.com/toss/suspensive/issues",
"repository": {
"type": "git",
"url": "https://github.com/toss/suspensive.git",
"directory": "packages/react-native"
},
"license": "MIT",
"author": "Jonghyeon Ko <[email protected]>",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./package.json": "./package.json"
},
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist",
"src"
],
"scripts": {
"build": "tsup",
"ci:attw": "attw --pack",
"ci:eslint": "eslint \"**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}\"",
"ci:publint": "publint --strict",
"ci:test": "jest",
"ci:test:watch": "vitest --ui --coverage --typecheck",
"ci:type": "tsc --noEmit",
"clean": "rimraf ./dist && rimraf ./coverage",
"dev": "tsup --watch",
"prepack": "pnpm build"
},
"dependencies": {
"@suspensive/utils": "workspace:*"
},
"devDependencies": {
"@suspensive/eslint-config": "workspace:*",
"@suspensive/tsconfig": "workspace:*",
"@suspensive/tsup": "workspace:*",
"@testing-library/react-native": "^12.5.2",
"@types/react": "^18.3.3",
"babel-jest": "^29.7.0",
"expo": "^51.0.22",
"jest": "^29.7.0",
"jest-expo": "^51.0.3",
"react": "^18.3.1",
"react-native": "0.74.3"
},
"peerDependencies": {
"react": "^18",
"react-native": "0.74.3"
},
"publishConfig": {
"access": "public"
}
}
5 changes: 5 additions & 0 deletions packages/react-native/src/TestText.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('<TestText />', () => {
it('should render text "Test" with custom text', () => {
expect(1).toBe(1)
})
})
3 changes: 3 additions & 0 deletions packages/react-native/src/TestText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Text } from 'react-native'

export const TestText = () => <Text>Test</Text>
1 change: 1 addition & 0 deletions packages/react-native/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { TestText } from './TestText'
7 changes: 7 additions & 0 deletions packages/react-native/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@suspensive/tsconfig/react-library.json",
"include": [".", "./.eslintrc.cjs", "./babel.config.cjs"],
"compilerOptions": {
"types": ["@testing-library/jest-dom/vitest", "vitest/globals"]
}
}
4 changes: 4 additions & 0 deletions packages/react-native/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { options } from '@suspensive/tsup'
import { defineConfig } from 'tsup'

export default defineConfig(options)
Loading

0 comments on commit b6e6920

Please sign in to comment.