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

astro-react-navigation

v0.0.6

Published

Hijack your Astro MPA with React Navigation's native-like routing

Downloads

30

Readme

astro-react-navigation

Integrate React Navigation to create a hybrid routing solution for Astro multi-page apps.

Part of a long-term experiment to create a universal next-gen router with the following features:

  • Isomorphic (hybrid SSR + client-side routing)
  • React framework-agnostic (initially with tight integration to Astro/Vite SSR)
  • First-class support for common mobile navigation patterns such as tabs, stacks, segments, modals, etc. Reference
  • Support RSC streaming, layouts & nested layouts [TODO]
  • 100% ESM-only exports [TODO]

Usage

1. Installation

Create a new Astro project or cd into an existing project. Ensure the Astro React plugin is installed, and then run the following commands (see note on alternate package managers below if not using pnpm):

  • pnpm add astro-react-navigation @react-navigation/native@next @react-navigation/stack@next react-native@npm:react-native-web-lite react-native-safe-area-context@npm:react-native-safe-area-context-web-vendored
  • pnpm add -D babel-preset-expo

Then add the following to your astro.config file:

import react from "@astrojs/react";
import reactNavigation from "astro-react-navigation";

plugins: [
    // Load the Astro React plugin first
    react({
        // This option should be omitted or explicitly set to false
        // because it triggers a bug in the way Astro resolves virtual
        // children nodes in React
        // experimentalReactChildren: false
    }),
    reactNavigation()
]

Finally, do this hacky workaround in a .pnpmfile.cjs in your project root (alternatively use npm overrides or yarn resolutions respectively if using either of these package managers):

// It's currently necessary to override the @react-navigation/elements deps required
// by @react-navigation/stack, because of some dodgy cjs asset imports which break the
// production build.
// Yarn users could put this package resolution inside `resolutions` within `package.json`
// instead.

function readPackage(pkg) {
    if (pkg.dependencies && pkg.dependencies["@react-navigation/elements"]) {
        pkg.dependencies["@react-navigation/elements"] = "github:jkhaui/react-navigation-lite#react-navigation-elements-v2.0.0-alpha.10-gitpkg"
    }
    return pkg
}

module.exports = {
    hooks: {
        readPackage
    }
}

Post-Install Quickstart

  1. Create a /react/index.tsx file in your project root and paste the following:
import * as React from 'react';
import {DarkTheme, NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import {SafeAreaProvider} from 'react-native-safe-area-context';

function Home({navigation}) {
    return (
        <div style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
            <h1>Home screen</h1>
            <button
                children="Go to Profile"
                onClick={() => navigation.navigate('Profile')}
            />
        </div>
    );
}

function Profile({navigation}) {
    return (
        <div style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
            <h1>Profile screen</h1>
            <button children="Go back" onClick={() => navigation.goBack()}/>
        </div>
    );
}

const Stack = createStackNavigator();

function MyStack() {
    return (
        <Stack.Navigator
            screenOptions={{
                headerShown: false,
            }}
        >
            <Stack.Screen
                name="Home"
                component={Home}
            />
            <Stack.Screen
                name="Profile"
                component={Profile}
            />
        </Stack.Navigator>
    );
}

export default function App() {
    const INITIAL_METRICS = {
         frame: {x: 0, y: 0, width: 0, height: 0},
         insets: {top: 0, left: 0, right: 0, bottom: 0},
    };

    return (
        <React.Fragment>
            <SafeAreaProvider initialMetrics={INITIAL_METRICS}>
                <NavigationContainer theme={DarkTheme}>
                    <MyStack/>
                </NavigationContainer>
            </SafeAreaProvider>
        </React.Fragment>
    );
}
  1. From your root Astro page, and be sure to add the client:load directive for immediate client-side hydration.
---
import App from "../components/react";
---

<App client:load />

You should now have the (very basic) example below working in your browser:

Demo

Caveats

This integration is for a fairly specific/niche use-case. It's only been tested with SSR and you probably shouldn't use it as-is in production. If the project actually progresses then it may one day have unit + e2e tests with appropriate test coverage.

Options

// Basic CSS applied to the page's HTML & body elements
// to ensrue the rendered navigation container does not initialize with a 
// height of 0.
// Defaults to true. 
injectGlobalStyles?: boolean;

// See https://github.com/expo/router/blob/d234a3237afa3595a5b30c595522b2ff7f296750/packages/expo-router/src/static/renderStaticContent.tsx#L23.
// Defaults to true.
resetGlobalElementsContext?: boolean;