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 🙏

© 2026 – Pkg Stats / Ryan Hefner

rn-sun-moon-switch

v1.0.0

Published

A beautiful animated sun/moon toggle switch component for React Native

Readme

🌞🌙 rn-sun-moon-switch

A beautiful animated sun/moon toggle switch component for React Native, powered by react-native-reanimated.

✨ Features

  • 🎨 Smooth animated transitions between sun and moon states
  • ⭐ Animated stars that appear during night mode
  • ☁️ Cloud animations
  • 📱 Fully compatible with React Native and Expo
  • 🔧 Built with TypeScript
  • 🎯 Zero dependencies (peer dependencies only)

📦 Installation

npm install rn-sun-moon-switch
# or
yarn add rn-sun-moon-switch

Peer Dependencies

This library requires the following peer dependencies:

  • react (any version)
  • react-native (any version)
  • react-native-reanimated (>= 2.0.0)

Make sure you have react-native-reanimated installed:

npm install react-native-reanimated
# or
yarn add react-native-reanimated

For Expo projects, react-native-reanimated is usually already included. For bare React Native projects, you may need to link the native module.

🚀 Quick Start

import React from 'react';
import { View, StyleSheet } from 'react-native';
import { SunMoonSwitch } from 'rn-sun-moon-switch';

export default function App() {
  return (
    <View style={styles.container}>
      <SunMoonSwitch />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff',
  },
});

📖 Usage

Basic Usage (Uncontrolled)

The component can manage its own state:

import { SunMoonSwitch } from 'rn-sun-moon-switch';

<SunMoonSwitch 
  onValueChange={(isLightMode) => {
    console.log('Theme:', isLightMode ? 'light' : 'dark');
  }}
/>

Controlled Mode (Recommended for Theme Switching)

Perfect for integrating with your app's theme system:

import React, { useState } from 'react';
import { SunMoonSwitch } from 'rn-sun-moon-switch';

function App() {
  const [isDarkMode, setIsDarkMode] = useState(false);

  return (
    <SunMoonSwitch 
      value={!isDarkMode}
      onValueChange={(isLightMode) => setIsDarkMode(!isLightMode)}
    />
  );
}

🎨 Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | value | boolean | undefined | Current value (true = light/day, false = dark/night). Makes component controlled. | | onValueChange | (value: boolean) => void | undefined | Callback fired when switch is toggled. | | defaultValue | boolean | true | Initial value for uncontrolled mode. | | dayBackgroundColor | string | "#3686ef" | Background color for light/day mode. | | nightBackgroundColor | string | "#333" | Background color for dark/night mode. | | animationDuration | number | 1500 | Animation duration in milliseconds. | | disabled | boolean | false | Disables user interaction. | | width | number | 180 | Width in pixels. Height is auto-calculated (3:1 ratio). | | style | ViewStyle | undefined | Additional style for the container. | | testID | string | undefined | Test ID for testing purposes. |

💡 Examples

Custom Colors

<SunMoonSwitch 
  dayBackgroundColor="#FFD700"
  nightBackgroundColor="#1a1a2e"
/>

Different Widths

<SunMoonSwitch width={120} /> {/* Smaller */}
<SunMoonSwitch width={180} /> {/* Default */}
<SunMoonSwitch width={240} /> {/* Larger */}

With Theme Context

import { useTheme } from './ThemeContext';

function ThemeSwitcher() {
  const { isDarkMode, toggleTheme } = useTheme();
  
  return (
    <SunMoonSwitch 
      value={!isDarkMode}
      onValueChange={toggleTheme}
    />
  );
}

See USAGE_EXAMPLES.md for more detailed examples including AsyncStorage integration and React Context usage.

🛠️ Development

To set up the development environment:

  1. Clone the repository:
git clone <repository-url>
cd rn-sun-moon-switch
  1. Install dependencies:
npm install
  1. Build the library:
npm run build
  1. Run the example app:
npm run example
# Then navigate to examples/ and run npm install if needed

Build Commands

  • npm run build - Build the library for production
  • npm run watch - Build in watch mode for development
  • npm run example - Start the example Expo app

📝 Examples

Check out the examples/ folder for a complete working example of the component in an Expo app.

To run the example:

cd examples
npm install
npm start

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT

🙏 Acknowledgments

Built with:


Made with ❤️ for the React Native community