Andrew Rhodes

Andrew Rhodes

1613647320

Create React Native Named StyleSheets with Support for Dark/Light/Auto Mode

react-native-themed-stylesheet

A package that allows you to create React Native StyleSheets with support for Dark/Light/Auto Themes.

  • Depends on react-native-appearance to choose the theme based on OS preference(Android 10/iOS 13)
  • Simple API
  • Fully typed
  • Builds on top of StyleSheets and Hooks
  • Storybook addon to change Theme Mode

Installation

Using Expo

expo install react-native-appearance react-native-themed-stylesheet

Using Yarn

yarn add react-native-appearance react-native-themed-stylesheet

Using NPM

npm install --save react-native-appearance react-native-themed-stylesheet

Usage

Creating the theme:

// theme.ts
import { createTheme } from 'react-native-themed-stylesheet'

const themes = {
  light: {
    textColor: '#ff0000'
  },
  dark: {
    textColor: '#fff'
  },
  common: { // Optional
    fontSize: 12
  }
}

const { ThemeProvider, useStyle, useTheme } = createTheme(themes, 'auto') // Initial Mode is optional(Default: 'auto')

export { ThemeProvider, useStyle, useTheme }

Using the theme:

// Components.tsx
import React from 'react'
import { View, Text, Button } from 'react-native'
import { ThemeProvider, useStyle, useTheme } from './theme'

const ComponentWithUseStyle: React.FC = () => {
  const styles = useStyle(theme => {
    text: {
      color: options.disabled ? '#C9C9C9' : theme.textColor,
      fontSize: theme.fontSize
    }
  })

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text style={styles.text}>Hello World</Text>
    </View>
  )
}

const ComponentWithUseTheme: React.FC = () => {
  const { theme, mode, setThemes, setMode } = useTheme()
  console.log('Current Mode:', mode)

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text style={{ color: theme.textColor, fontSize: theme.fontSize }}>Hello World</Text>
      <Button title='Dark Mode' onPress={() => setMode('dark')}/>
      <Button title='Light Mode' onPress={() => setMode('light')}/>
      <Button title='Auto Mode' onPress={() => setMode('auto')}/>
      <Button title='Change Themes' onPress={
          () => setThemes({
            light: {
              textColor: '#ffff00'
            },
            dark: {
              textColor: '#C9C9C9'
            },
            common: {
              fontSize: 14
            }
          })
        }
      />
    </View>
  )
}

Storybook Addon

Installation:

// storybook.js
import {
  getStorybookUI,
  configure,
  addDecorator,
  addParameters
} from '@storybook/react-native'
import { withThemeHook } from 'react-native-themed-stylesheet/storybook'
import 'react-native-themed-stylesheet/storybook/register'
import { useTheme } from './theme'

addDecorator(withThemeHook)
addParameters({
  useTheme
})

configure(() => {
  require('path/to/some/story')
}, module)

const StorybookUIRoot = getStorybookUI()

export default StorybookUIRoot // Make sure to use this component within ThemeProvider.

API

Function: createTheme(themes, [initialMode])

Use this function to create the theme.

Parameters

  • themes: An object containing light, dark and an optional common theme(Will be merge with boths themes).
  • initialMode: A string(‘light’, ‘dark’ or ‘auto’) specifying the initial mode(Default: ‘auto’).

Returns


ThemeObject


Object: ThemeObject

An object containing the following properties:

  • ThemeProvider: Theme Provider.
  • useStyle: Hook to create Named StyleSheets.
  • useTheme: Hook to get access to ThemeContext.

React Component: ThemeProvider

A react component to provide ThemeContext.


Function: useStyle(createStyles)

Hook to create themed stylesheets.

Parameters

  • createStyles: A function that receives the current theme and returns an object of type T.

Returns


StyleSheet.NamedStyles<T>


Function: useTheme()

Hook to get access to theme context.

Returns


{ theme, mode, setThemes, setMode }

An object containing the following properties:

  • theme: The current theme.
  • mode: The current mode.
  • setThemes: Function to set the themes(The same type of createTheme themes param).
  • setMode: Function to set the mode(‘light’, ‘dark’ or ‘auto’).

Download Details:

Author: andreppedroza

Source Code: https://github.com/andreppedroza/react-native-themed-stylesheet

#react-native #react #mobile-apps

What is GEEK

Buddha Community

Create React Native Named StyleSheets with Support for Dark/Light/Auto Mode
Autumn  Blick

Autumn Blick

1598839687

How native is React Native? | React Native vs Native App Development

If you are undertaking a mobile app development for your start-up or enterprise, you are likely wondering whether to use React Native. As a popular development framework, React Native helps you to develop near-native mobile apps. However, you are probably also wondering how close you can get to a native app by using React Native. How native is React Native?

In the article, we discuss the similarities between native mobile development and development using React Native. We also touch upon where they differ and how to bridge the gaps. Read on.

A brief introduction to React Native

Let’s briefly set the context first. We will briefly touch upon what React Native is and how it differs from earlier hybrid frameworks.

React Native is a popular JavaScript framework that Facebook has created. You can use this open-source framework to code natively rendering Android and iOS mobile apps. You can use it to develop web apps too.

Facebook has developed React Native based on React, its JavaScript library. The first release of React Native came in March 2015. At the time of writing this article, the latest stable release of React Native is 0.62.0, and it was released in March 2020.

Although relatively new, React Native has acquired a high degree of popularity. The “Stack Overflow Developer Survey 2019” report identifies it as the 8th most loved framework. Facebook, Walmart, and Bloomberg are some of the top companies that use React Native.

The popularity of React Native comes from its advantages. Some of its advantages are as follows:

  • Performance: It delivers optimal performance.
  • Cross-platform development: You can develop both Android and iOS apps with it. The reuse of code expedites development and reduces costs.
  • UI design: React Native enables you to design simple and responsive UI for your mobile app.
  • 3rd party plugins: This framework supports 3rd party plugins.
  • Developer community: A vibrant community of developers support React Native.

Why React Native is fundamentally different from earlier hybrid frameworks

Are you wondering whether React Native is just another of those hybrid frameworks like Ionic or Cordova? It’s not! React Native is fundamentally different from these earlier hybrid frameworks.

React Native is very close to native. Consider the following aspects as described on the React Native website:

  • Access to many native platforms features: The primitives of React Native render to native platform UI. This means that your React Native app will use many native platform APIs as native apps would do.
  • Near-native user experience: React Native provides several native components, and these are platform agnostic.
  • The ease of accessing native APIs: React Native uses a declarative UI paradigm. This enables React Native to interact easily with native platform APIs since React Native wraps existing native code.

Due to these factors, React Native offers many more advantages compared to those earlier hybrid frameworks. We now review them.

#android app #frontend #ios app #mobile app development #benefits of react native #is react native good for mobile app development #native vs #pros and cons of react native #react mobile development #react native development #react native experience #react native framework #react native ios vs android #react native pros and cons #react native vs android #react native vs native #react native vs native performance #react vs native #why react native #why use react native

How To Create Dark and Light Mode Website using jQuery

Hello Friends,

In this tutorial i will show you How To Create Dark and Light Mode Website using jQuery.

As you can see many website and mobile applications are provide light theme as well as dark theme to user, It is useful for websites which have long content and requires users to focus on the screen for a long time.

Read More : How To Create Dark and Light Mode Website using jQuery

https://websolutionstuff.com/post/how-to-create-dark-and-light-mode-website-using-jquery


Read Also : How To Generate Barcode In Laravel

https://websolutionstuff.com/post/how-to-generate-barcode-in-laravel

#how to create dark and light mode website using jquery #dark and light mode #how to add dark mode and light mode in website #day and night mode #jquery

How To Toggle Dark and Light Mode using jQuery

Hello Guys,

In this tutorial I will show you how to toggle between dark and light mode using jQuery.

As per the current trend of web development in many websites provides to user for reading select theme like dark mode and light mode or day mode and night mode of website and it’s very easy to implement in website.

In this just write some css code and java script for toggle dark mode and light mode website also you can store in local storage for save the state of user select theme like dark mode and light of website.

Read More : How To Toggle Dark and Light Mode using jQuery

https://websolutionstuff.com/post/how-to-toggle-dark-and-light-mode-using-jquery


Read Also : How Generate PDF From HTML View In Laravel

https://websolutionstuff.com/post/how-generate-pdf-from-html-view-in-laravel

#how to toggle dark and light mode using jquery #dark and light mode #toggle between light and dark mode #jquery #day and night mode #dark mode website

Hire Dedicated React Native Developer

Have you ever thought of having your own app that runs smoothly over multiple platforms?

React Native is an open-source cross-platform mobile application framework which is a great option to create mobile apps for both Android and iOS. Hire Dedicated React Native Developer from top React Native development company, HourlyDeveloper.io to design a spectacular React Native application for your business.

Consult with experts:- https://bit.ly/2A8L4vz

#hire dedicated react native developer #react native development company #react native development services #react native development #react native developer #react native

Hire Dedicated React Native Developers - WebClues Infotech

Being one of the emerging frameworks for app development the need to develop react native apps has increased over the years.

Looking for a react native developer?

Worry not! WebClues infotech offers services to Hire React Native Developers for your app development needs. We at WebClues Infotech offer a wide range of Web & Mobile App Development services based o your business or Startup requirement for Android and iOS apps.

WebClues Infotech also has a flexible method of cost calculation for hiring react native developers such as Hourly, Weekly, or Project Basis.

Want to get your app idea into reality with a react native framework?

Get in touch with us.

Hire React Native Developer Now: https://www.webcluesinfotech.com/hire-react-native-app-developer/

For inquiry: https://www.webcluesinfotech.com/contact-us/

Email: sales@webcluesinfotech.com

#hire react native developers #hire dedicated react native developers #hire react native developer #hiring a react native developer #hire freelance react native developers #hire react native developers in 1 hour