• Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hooks for React Native web and Expo

react-native-web-hooks

Hooks for implementing complex functionality in React Native for web and Expo.

A closer look at how the hooks work here.

Installation

yarn add react-native-web-hooks

or

npm install --save react-native-web-hooks

Usage - Hooks

Import the library into your JavaScript file:

import {
  useDimensions,
  useActive,
  useFocus,
  useHover,
  useREM,
  useScaledSize,
} from 'react-native-web-hooks';

Get REM size

Use these in place of rem font sizes like: font-size: 1.3rem.

Note: this isn't a hook anymore and will be moved out in the future.

const fontSize = useREM(1.3);

return <Text style={{ fontSize }} />;

Get scaled font size

These change based on the width of the screen.

const fontSize = useScaledSize(1.5);

return <Text style={{ fontSize }} />;

Get dimensions

Note that fontScale is hard-coded to 1 on the react-native-web side and shouldn't be used to calculate dynamic font sizes.

const {
  window: { width, height, fontScale, scale },
  screen,
} = useDimensions();

Measure a view

It's best to style a view based on that own view's size and not the window size. To make this easier you can use the useLayout hook!

🚨 Using onLayout may require you to install resize-observer-polyfill. Learn more in the official Expo docs

const {
  onLayout,
  width,
  height,
  x,
  y
} = useLayout();

return <View onLayout={onLayout} />

Create pseudo class styles

These will be replaced by React Flare when it's released.

import { useRef } from 'react';
import { StyleSheet, Linking, Text, Platform } from 'react-native';

import { useHover, useFocus, useActive } from 'react-native-web-hooks';

function Link({ children, href = '#' }) {
  const ref = useRef(null);

  const isHovered = useHover(ref);
  const isFocused = useFocus(ref);
  const isActive = useActive(ref);

  return (
    <Text
      accessibilityRole="link"
      href={href}
      draggable={false}
      onPress={() => Linking.openURL(href)}
      tabIndex={0}
      ref={ref}
      style={[
        styles.text,
        isHovered && styles.hover,
        isFocused && styles.focused,
        isActive && styles.active,
      ]}>
      {children}
    </Text>
  );
}

const styles = StyleSheet.create({
  text: {
    ...Platform.select({
      web: {
        cursor: 'pointer',
        outlineStyle: 'none',
        borderBottomWidth: 1,
        borderBottomColor: 'transparent',
        transitionDuration: '200ms',
      },
      default: {},
    }),
  },
  active: {
    color: 'blue',
    borderBottomColor: 'blue',
    opacity: 1.0,
  },
  hover: {
    opacity: 0.6,
  },
  focused: {
    borderBottomColor: 'black',
  },
});

Usage - Render Props

Import the library into your JavaScript file:

import { Hoverable, Resizable } from 'react-native-web-hooks';

You can wrap a function or a component.

import React, { Component } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import { Hoverable } from 'react-native-web-hooks';

const createLogger = (...msg) => () => {
  console.log(...msg);
};

class App extends Component {
  render() {
    return (
      <View>
        <Hoverable onHoverIn={createLogger('start hover')} onHoverOut={createLogger('end hover')}>
          {isHovered => (
            <TouchableOpacity accessible style={{ backgroundColor: isHovered ? '#333' : '#fff' }}>
              <Text>Welcome to React</Text>}
            </TouchableOpacity>
          )}
        </Hoverable>
      </View>
    );
  }
}

Observe window resize events.

return (
  <Resizable>
    {layout => <View style={{ width: layout.width / 2, height: layout.width / 2 }} />}
  </Resizable>
);

More Repositories

1

Expo-Crossy-Road

🐥🚙 Crossy Road game clone made in Expo (iOS, Android, web), THREE.js, Tween, React Native. 🐔
JavaScript
977
star
2

firebase-instagram

📸 Instagram clone with Firebase Cloud Firestore, Expo, and React Native 😁😍
JavaScript
431
star
3

pillar-valley

👾A cross-platform video game built with Expo, three.js, and Firebase! 🎮🕹
TypeScript
302
star
4

Instagram

A universal instagram clone built with Expo
JavaScript
295
star
5

AWESOME-REACT-NATIVE-WEB

💙 React Native Web patterns, techniques, tips, and tricks ✨
237
star
6

expo-native-firebase

🔥 Native Firebase Expo App (iOS, Android) Demo for Firestore, Notifications, Analytics, Storage, Messaging, Database 🚨
JavaScript
209
star
7

Expo-Voxel

🎮🌳 Voxel Terrain made in React Native. ∛
JavaScript
184
star
8

expo-dark-mode-switch

A beautiful React dark mode switch component for iOS, Android, and Web
TypeScript
151
star
9

expo-router-twitter

Expo Router Twitter clone
TypeScript
145
star
10

expo-mdx

An attempt to render MDX universally across platforms
TypeScript
137
star
11

expo-auto-navigation

Test automatic navigation using Expo and React Navigation
TypeScript
128
star
12

metro-minify-esbuild

Use ESBuild to make your React Native code bundle faster.
JavaScript
116
star
13

expo-router-instagram-layout

Responsive Instagram layout clone. Built with Expo Router v2.
TypeScript
101
star
14

expo-router-layouts-example

Example of using custom layouts with Expo Router
TypeScript
91
star
15

expo-three-demo

🍎👩‍🏫 Collection of Demos for THREE.js in Expo!
JavaScript
87
star
16

icon-builder

website that helps build simple icons for React Native apps
TypeScript
83
star
17

snake

🐍🎮 Snake game made with Expo & PIXI.js 👾 iOS, Android, and Web
JavaScript
82
star
18

Lego-Expo

Play with Lego bricks anywhere using Expo
JavaScript
80
star
19

Sunset-Cyberspace

🎮👾Retro-runner Game made in Expo, Three.js, OpenGL, WebGL, Tween. 🕹
JavaScript
76
star
20

css-to-expo-linear-gradient

Convert a CSS linear gradient function to expo-linear-gradient props
TypeScript
67
star
21

react-flappy-bird

A side-scroller where the player controls a bird, attempting to fly between columns of green pipes without hitting them.
JavaScript
67
star
22

Portfolio

Expo Router Portfolio
TypeScript
64
star
23

expo-ahap

React Native module for loading and interacting with Apple ahap files
TypeScript
62
star
24

react-native-pixi

Use: https://github.com/expo/expo-pixi
JavaScript
60
star
25

apple-notes

A clone of the Apple Notes app but made universally with Expo
JavaScript
54
star
26

expo-three-orbit-controls

🎥 Three.js Orbit Controls (Camera) bridged into React Native
TypeScript
53
star
27

xcparse

super fast pbxproj parser written in TypeScript
TypeScript
46
star
28

expo-doodle-jump

JavaScript
44
star
29

expo-auto-navigation-webpack

Test automatic navigation using Expo and React Navigation and Webpack
TypeScript
40
star
30

react-native-pantry-storage

Persist values in `AsyncStorage` with expiration dates.
JavaScript
37
star
31

ExpoKit-Fastlane-Example

ExpoKit is deprecated. Everything here is automatic with EAS.
Ruby
35
star
32

expo-google-sign-in-demo

A demo for using native Google Auth in Expo with expo-google-sign-in
JavaScript
35
star
33

react-shadow-generator

Visually create React Native shadows in the browser
JavaScript
34
star
34

expo-progress

Simple progress components for Expo
TypeScript
33
star
35

expo-chroma-key-camera

Live green-screen effect with Expo and THREE.js
JavaScript
33
star
36

expo-background-color

[UNOFFICIAL] stack based React component for updating the native background color
TypeScript
32
star
37

link-native-assets-expo-config-plugin

TypeScript
30
star
38

react-native-ink

React Native for CLIs
TypeScript
30
star
39

react-bluetooth

Web Bluetooth API in React
TypeScript
28
star
40

pro-chat

Full featured chat app built with 💙 Expo & Firebase 🔥
JavaScript
27
star
41

react-xib

React for Apple Interface Builder
26
star
42

Expo-Super-Mario-World

Native Super Mario World in Expo
JavaScript
24
star
43

react-nothing

React renderer for nothing
JavaScript
23
star
44

Expo-Flash-List-Demo

Demo of @shopify/flash-list with an Expo Dev Client (Runnable iOS demo included)
TypeScript
23
star
45

Expo-Badge

A design study for Expo badges
22
star
46

gadd

download and install node modules from a GitHub monorepo
JavaScript
22
star
47

react-navigation-web-responsive-tabs-demo

JavaScript
21
star
48

App-Store-Connect-OpenAPI-Spec

Automatically tracks every copy of the App Store Connect OpenAPI JSON Spec
TypeScript
21
star
49

expo-router-tailwind-demo

Demo of using Expo Router with Tailwind in a website bundled using Metro
JavaScript
20
star
50

expo-dom-components-canary-example

Early preview of using DOM Components with Expo
TypeScript
19
star
51

expo-three-text

JavaScript
19
star
52

expo-rpg

👾🎮 2D Game built with expo/three.js - BETA, not even close to complete
JavaScript
19
star
53

Cel-Shader

SceneKit Cel Shader Example
Swift
19
star
54

Metro-Context-Modules-Demo

A demo of using the new require.context syntax in Expo with Metro bundler
TypeScript
18
star
55

baconet

Dogfooding expo router, metro web, eas
TypeScript
17
star
56

expo-skia-demo

Demo of using `@shopify/react-native-skia` with Expo for web
TypeScript
16
star
57

expo-dropbox

Example universal Expo app using the dropbox API
TypeScript
16
star
58

Expo-Nitro-Roll

A cross-platform video game built with Expo and three.js!
JavaScript
16
star
59

app-icon-endpoint

Cloud function to generate basic icons, splash screens, and favicons.
TypeScript
15
star
60

expo-zip-code

This app shows you the bounds of the zip code you are in!
JavaScript
15
star
61

expo-three-template

Template for building three.js apps in expo
JavaScript
12
star
62

react-native-fastest-image

The fastest most reliable Image component for React Native
TypeScript
12
star
63

expo-router-react-native-bottom-tabs

Demo of using react-native-bottom-tabs with Expo Router
TypeScript
11
star
64

Expo-PencilKit

Package for using Apple PencilKit with Expo Dev Clients.
Java
11
star
65

Metro-web-demo

Demo of using Metro to bundle Expo apps for web
TypeScript
10
star
66

react-native-facial-gestures

Track facial gestures with ease using front facing AR on the iPhoneX
JavaScript
10
star
67

expo-router-tabs-demo

The Expo Tabs template implemented using Expo Router
TypeScript
10
star
68

expo-cel-shader

A simple demo showing how to setup cel shading in react native with three.js and EXGL
TypeScript
10
star
69

Canny-Stream-Demo

TypeScript
9
star
70

Expo-Yandhi

The Yandhi demo created with Expo AR
JavaScript
9
star
71

expo-swift-example

Example of writing Swift modules in Expo
Ruby
9
star
72

react-europe-2019

Resources from my workshops and talk at React Europe 2019
JavaScript
9
star
73

expo-splash-video-example

Recreation of the "Universe - Website builder" animated splash screen effect, using Expo
TypeScript
9
star
74

App.js-Conf-Workshop-2022

Resources for the App.js Conf Workshop 2022 hosted by Evan Bacon and Lydia Hallie
TypeScript
8
star
75

expo-router-top-tabs

experimental
TypeScript
8
star
76

expo-sucrase-demo

Example of using sucrase to bundle an Expo project instead of Babel
JavaScript
8
star
77

react-native-permissions-tutorial

A tutorial on using permissions in React Native
JavaScript
8
star
78

basic-expo-app

pay no attention
JavaScript
7
star
79

expo-phaser-isometric

Phaser isometric game material
JavaScript
7
star
80

expo-icon-explore

Explore expo/vector-icons in the browser. Written with Expo Router
TypeScript
7
star
81

expo-dancing-stormtrooper

An AR clone dancing to the cantina bar song. This demonstrates setting up a 3D app, Collada (.dae) model loading, texture loading, playing audio
JavaScript
7
star
82

expo-dev.to

dev.to clone written using Expo (iOS, Android, web)
JavaScript
6
star
83

expo-swift-template

Using swift with Expo
Java
6
star
84

expo-safari-extension-test

Test a few different concepts to improve the Safari Extension development workflow for Expo users.
Objective-C++
6
star
85

app.js-conf

Resources from my App.js conf talk
6
star
86

config-plugins-for-any-platform

Expo config plugins for any platform
C#
6
star
87

Expo-App-Clip-experiment

For reference purposes only, do not use
TypeScript
6
star
88

expo-touch-bar-example

Example of creating a custom button in the touch bar using Expo/Electron
JavaScript
6
star
89

arc-browser-pull-to-refresh-haptics-in-Expo

Replicating the iOS pull-to-refresh progressive haptics effect from arc browser in an Expo app.
TypeScript
6
star
90

React-Europe-2018

Gaming resources from React Europe 2018
JavaScript
5
star
91

FacialRecognitionEmojiSearch

🙂🙃 Search for emojis using facial recognition. Built in Swift targeted for iOS 9.3+
Swift
5
star
92

anime-lorem

Anime placeholder photos
5
star
93

expo-router-better-web-drawers-example

An example of using web-only components to create high-performing drawers on web platforms
TypeScript
5
star
94

expo-firebase-tutorial

Java
5
star
95

Map-Skins

Swift 3. iOS Custom Dark or Light Maps. Super easy 😍
Swift
4
star
96

love-game

Lua
4
star
97

expo-config-plugins-splash-api

Example of using the internal expo-splash-screen config plugin API
TypeScript
4
star
98

fake-auth

A website for testing oauth redirects
TypeScript
4
star
99

react-apple-authentication

JavaScript
4
star
100

Expo-Orientation

JavaScript
4
star