Skip to content

Commit

Permalink
feat: ✨ introduce separate package for navigation integration (#152)
Browse files Browse the repository at this point in the history
* feat: ✨ introduce separate package for navigation integration

* fix: 🐛 centralize tsconfig

* fix: expo example

* fix: 🐛 package.json definitions
  • Loading branch information
okwasniewski authored Nov 18, 2024
1 parent f35cf37 commit c6f9a8f
Show file tree
Hide file tree
Showing 41 changed files with 377 additions and 425 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ module.exports = {
},
],
},
ignorePatterns: ['**/lib/**', '**/dist/**', '**/node_modules/**'],
ignorePatterns: [
'**/lib/**',
'**/dist/**',
'**/node_modules/**',
'expo-env.d.ts',
],
};
2 changes: 1 addition & 1 deletion apps/example-expo/app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import { withLayoutContext } from 'expo-router';
import createNativeBottomTabNavigator from '../../../../packages/react-native-bottom-tabs/src/react-navigation/navigators/createNativeBottomTabNavigator';
import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation';

const Tabs = withLayoutContext(createNativeBottomTabNavigator().Navigator);

Expand Down
10 changes: 5 additions & 5 deletions apps/example-expo/app/(tabs)/explore.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { StyleSheet, Image } from 'react-native';

import { Collapsible } from '@/components/Collapsible';
import { ExternalLink } from '@/components/ExternalLink';
import { ThemedText } from '@/components/ThemedText';
import { ThemedView } from '@/components/ThemedView';
import { Collapsible } from '../../components/Collapsible';
import { ExternalLink } from '../../components/ExternalLink';
import { ThemedText } from '../../components/ThemedText';
import { ThemedView } from '../../components/ThemedView';
import { ScrollView } from 'react-native-gesture-handler';

function TabTwoScreen() {
Expand Down Expand Up @@ -46,7 +46,7 @@ function TabTwoScreen() {
provide files for different screen densities
</ThemedText>
<Image
source={require('@/assets/images/react-logo.png')}
source={require('../../assets/images/react-logo.png')}
style={{ alignSelf: 'center' }}

Check warning on line 50 in apps/example-expo/app/(tabs)/explore.tsx

View workflow job for this annotation

GitHub Actions / lint

Inline style: { alignSelf: 'center' }
/>
<ExternalLink href="https://reactnative.dev/docs/images">
Expand Down
4 changes: 2 additions & 2 deletions apps/example-expo/app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ScrollView, StyleSheet, Platform } from 'react-native';

import { ThemedText } from '@/components/ThemedText';
import { ThemedView } from '@/components/ThemedView';
import { ThemedText } from '../../components/ThemedText';
import { ThemedView } from '../../components/ThemedView';

function HomeScreen() {
return (
Expand Down
4 changes: 2 additions & 2 deletions apps/example-expo/app/+not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Link, Stack } from 'expo-router';
import { StyleSheet } from 'react-native';

import { ThemedText } from '@/components/ThemedText';
import { ThemedView } from '@/components/ThemedView';
import { ThemedText } from '../components/ThemedText';
import { ThemedView } from '../components/ThemedView';

export default function NotFoundScreen() {
return (
Expand Down
2 changes: 1 addition & 1 deletion apps/example-expo/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as SplashScreen from 'expo-splash-screen';
import { StatusBar } from 'expo-status-bar';
import { useEffect } from 'react';

import { useColorScheme } from '@/hooks/useColorScheme';
import { useColorScheme } from '../hooks/useColorScheme';

// Prevent the splash screen from auto-hiding before asset loading is complete.
SplashScreen.preventAutoHideAsync();
Expand Down
52 changes: 37 additions & 15 deletions apps/example-expo/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
const path = require('path');
const pak = require('../../packages/react-native-bottom-tabs/package.json');
const fs = require('fs');

module.exports = {
presets: ['babel-preset-expo'],
plugins: [
[
'module-resolver',
const packages = path.resolve(__dirname, '..', '..', 'packages');

/** @type {import('@babel/core').TransformOptions} */
module.exports = function (api) {
api.cache(true);

const alias = Object.fromEntries(
fs
.readdirSync(packages)
.filter((name) => !name.startsWith('.'))
.map((name) => {
const pak = require(`../../packages/${name}/package.json`);

if (pak.source == null) {
return null;
}

return [pak.name, path.resolve(packages, name, pak.source)];
})
.filter(Boolean)
);

return {
presets: ['babel-preset-expo'],
overrides: [
{
extensions: ['.tsx', '.ts', '.js', '.json'],
alias: {
'react-native-bottom-tabs': path.join(
__dirname,
'../../packages/react-native-bottom-tabs',
pak.source
),
},
exclude: /\/node_modules\//,
plugins: [
[
'module-resolver',
{
extensions: ['.tsx', '.ts', '.js', '.json'],
alias,
},
],
],
},
],
],
};
};
4 changes: 2 additions & 2 deletions apps/example-expo/components/Collapsible.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PropsWithChildren, useState } from 'react';
import { StyleSheet, TouchableOpacity } from 'react-native';

import { ThemedText } from '@/components/ThemedText';
import { ThemedView } from '@/components/ThemedView';
import { ThemedText } from './ThemedText';
import { ThemedView } from './ThemedView';

export function Collapsible({
children,
Expand Down
2 changes: 1 addition & 1 deletion apps/example-expo/components/ThemedText.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Text, type TextProps, StyleSheet } from 'react-native';

import { useThemeColor } from '@/hooks/useThemeColor';
import { useThemeColor } from '../hooks/useThemeColor';

export type ThemedTextProps = TextProps & {
lightColor?: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/example-expo/components/ThemedView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { View, type ViewProps } from 'react-native';

import { useThemeColor } from '@/hooks/useThemeColor';
import { useThemeColor } from '../hooks/useThemeColor';

export type ThemedViewProps = ViewProps & {
lightColor?: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/example-expo/hooks/useThemeColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { useColorScheme } from 'react-native';

import { Colors } from '@/constants/Colors';
import { Colors } from '../constants/Colors';

export function useThemeColor(
props: { light?: string; dark?: string },
Expand Down
2 changes: 1 addition & 1 deletion apps/example-expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"preset": "jest-expo"
},
"dependencies": {
"@bottom-tabs/react-navigation": "*",
"@expo/vector-icons": "^14.0.2",
"@react-navigation/bottom-tabs": "^6.1.18",
"@react-navigation/native": "^6.1.18",
"expo": "~51.0.39",
"expo-build-properties": "~0.12.5",
Expand Down
23 changes: 10 additions & 13 deletions apps/example-expo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true,
"paths": {
"react-native-bottom-tabs": [
"../../packages/react-native-bottom-tabs/src/index"
],
"react-native-bottom-tabs/react-navigation": [
"../../packages/react-native-bottom-tabs/src/react-navigation/index"
],
"@/*": [
"./*"
]
"extends": "../../tsconfig.json",
"references": [
{
"path": "../../packages/react-native-bottom-tabs"
},
{
"path": "../../packages/react-navigation"
}
],
"compilerOptions": {
"rootDir": "."
},
"include": [
"**/*.ts",
Expand Down
52 changes: 37 additions & 15 deletions apps/example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
const path = require('path');
const pak = require('../../packages/react-native-bottom-tabs/package.json');
const fs = require('fs');

module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: [
[
'module-resolver',
const packages = path.resolve(__dirname, '..', '..', 'packages');

/** @type {import('@babel/core').TransformOptions} */
module.exports = function (api) {
api.cache(true);

const alias = Object.fromEntries(
fs
.readdirSync(packages)
.filter((name) => !name.startsWith('.'))
.map((name) => {
const pak = require(`../../packages/${name}/package.json`);

if (pak.source == null) {
return null;
}

return [pak.name, path.resolve(packages, name, pak.source)];
})
.filter(Boolean)
);

return {
presets: ['module:@react-native/babel-preset'],
overrides: [
{
extensions: ['.tsx', '.ts', '.js', '.json'],
alias: {
'react-native-bottom-tabs': path.join(
__dirname,
'../../packages/react-native-bottom-tabs',
pak.source
),
},
exclude: /\/node_modules\//,
plugins: [
[
'module-resolver',
{
extensions: ['.tsx', '.ts', '.js', '.json'],
alias,
},
],
],
},
],
],
};
};
1 change: 1 addition & 0 deletions apps/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"visionos": "react-native run-visionos"
},
"dependencies": {
"@bottom-tabs/react-navigation": "*",
"@callstack/react-native-visionos": "^0.75.0",
"@react-navigation/bottom-tabs": "^6.6.1",
"@react-navigation/native": "^6.1.18",
Expand Down
1 change: 0 additions & 1 deletion apps/example/src/Examples/JSBottomTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { Article } from '../Screens/Article';
import { Albums } from '../Screens/Albums';
Expand Down
4 changes: 1 addition & 3 deletions apps/example/src/Examples/NativeBottomTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as React from 'react';
import { Article } from '../Screens/Article';
import { Albums } from '../Screens/Albums';
import { Contacts } from '../Screens/Contacts';
import { Chat } from '../Screens/Chat';
// This import works properly when library is published
import createNativeBottomTabNavigator from '../../../../packages/react-native-bottom-tabs/src/react-navigation/navigators/createNativeBottomTabNavigator';
import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation';
import { Platform } from 'react-native';

const Tab = createNativeBottomTabNavigator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Article } from '../Screens/Article';
import { Albums } from '../Screens/Albums';
import { Contacts } from '../Screens/Contacts';
import { Chat } from '../Screens/Chat';
import createNativeBottomTabNavigator from '../../../../packages/react-native-bottom-tabs/src/react-navigation/navigators/createNativeBottomTabNavigator';
import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation';
import { createNativeStackNavigator } from '@react-navigation/native-stack';

const headerOptions = {
Expand Down
4 changes: 1 addition & 3 deletions apps/example/src/Examples/NativeBottomTabsRemoteIcons.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as React from 'react';
import { Article } from '../Screens/Article';
import { Albums } from '../Screens/Albums';
import { Contacts } from '../Screens/Contacts';
import { Chat } from '../Screens/Chat';
// This import works properly when library is published
import createNativeBottomTabNavigator from '../../../../packages/react-native-bottom-tabs/src/react-navigation/navigators/createNativeBottomTabNavigator';
import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation';

const Tab = createNativeBottomTabNavigator();

Expand Down
4 changes: 1 addition & 3 deletions apps/example/src/Examples/NativeBottomTabsSVGs.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as React from 'react';
import { Article } from '../Screens/Article';
import { Albums } from '../Screens/Albums';
import { Contacts } from '../Screens/Contacts';
import { Chat } from '../Screens/Chat';
// This import works properly when library is published
import createNativeBottomTabNavigator from '../../../../packages/react-native-bottom-tabs/src/react-navigation/navigators/createNativeBottomTabNavigator';
import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation';

const Tab = createNativeBottomTabNavigator();

Expand Down
4 changes: 1 addition & 3 deletions apps/example/src/Examples/NativeBottomTabsVectorIcons.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as React from 'react';
import { Article } from '../Screens/Article';
import { Albums } from '../Screens/Albums';
import { Contacts } from '../Screens/Contacts';
import { Chat } from '../Screens/Chat';
// This import works properly when library is published
import createNativeBottomTabNavigator from '../../../../packages/react-native-bottom-tabs/src/react-navigation/navigators/createNativeBottomTabNavigator';
import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation';
import { Platform } from 'react-native';

import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
Expand Down
1 change: 0 additions & 1 deletion apps/example/src/Examples/SFSymbols.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import TabView, { SceneMap } from 'react-native-bottom-tabs';
import { useState } from 'react';
import { Article } from '../Screens/Article';
Expand Down
1 change: 0 additions & 1 deletion apps/example/src/Examples/ThreeTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import TabView, { SceneMap } from 'react-native-bottom-tabs';
import { useState } from 'react';
import { Article } from '../Screens/Article';
Expand Down
32 changes: 6 additions & 26 deletions apps/example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
{
"extends": "../../tsconfig",
"references": [
{ "path": "../../packages/react-native-bottom-tabs" },
{ "path": "../../packages/react-navigation" },
],
"compilerOptions": {
"paths": {
"react-native-bottom-tabs": ["../../packages/react-native-bottom-tabs/src/index"],
"react-native-bottom-tabs/react-navigation": [
"../../packages/react-native-bottom-tabs/src/react-navigation/index"
]
},
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-jsx",
"lib": ["ESNext"],
"module": "ESNext",
"moduleResolution": "Bundler",
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noStrictGenericChecks": false,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "ESNext",
"verbatimModuleSyntax": true
"rootDir": "."
}
}
Loading

0 comments on commit c6f9a8f

Please sign in to comment.