Skip to content

Instantly share code, notes, and snippets.

Baking apps with react-native-macos

Alec Larson aleclarson

Baking apps with react-native-macos
View GitHub Profile
aleclarson / ssl-dev.patch
Last active Jul 17, 2020
Trust all SSL certificates in React Native (in development only)
View ssl-dev.patch
diff --git a/node_modules/react-native/Libraries/Network/ b/node_modules/react-native/Libraries/Network/
index 274f381..3b573dc 100644
--- a/node_modules/react-native/Libraries/Network/
+++ b/node_modules/react-native/Libraries/Network/
@@ -108,6 +108,15 @@ - (void)cancelRequest:(NSURLSessionDataTask *)task
#pragma mark - NSURLSession delegate
+#if DEBUG
+- (void)URLSession:(NSURLSession *)session
View Nothing.h
#import <AppKit/AppKit.h>
// This window becomes main and key when the app loses focus, which ensures
// the "didBecomeKey" and "didBecomeMain" events are posted when they should be.
@interface Nothing : NSWindow <NSWindowDelegate>
- (instancetype)init;
- (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag NS_DESIGNATED_INITIALIZER;
View react-update-url-on-scroll+3.5.0.patch
diff --git a/node_modules/react-update-url-on-scroll/lib/Manager.js b/node_modules/react-update-url-on-scroll/lib/Manager.js
index 6e8de9f..7cb49c4 100644
--- a/node_modules/react-update-url-on-scroll/lib/Manager.js
+++ b/node_modules/react-update-url-on-scroll/lib/Manager.js
@@ -18,11 +18,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var defaultConfig = {
affectHistory: false,
- debounce: 100,
keepLastAnchorHash: false,
View encodeForm.ts
import { is } from 'is'
import { Lookup } from 'types'
// Reuse one array for all encoding.
const pairs: string[] = []
export function encodeForm(values: Lookup) {
for (const key in values) {
encodePair(key, values[key])
aleclarson / unmount.tsx
Created Nov 2, 2019
React controlled unmount
View unmount.tsx
import React from 'react'
import { animated, useSpring } from 'react-spring'
const Example = () => {
const [unmount, isUnmounting] = React.useUnmount()
const { opacity } = useSpring({
// Fade in "opacity" from 0
from: { opacity: 0 },
// Fade out "opacity" to 0 when ready to unmount
View roundToStep.ts
function roundToStep(n: number, step: number) {
n = Math.round(n / step) * step
// Determine the number of decimals to round.
let p = 0
if (n % 1) {
const s = String(n)
p = s.length - s.indexOf('.') - 1
View app.tsx
import { createHook } from './createHook'
class App {
count = 0
increaseCount() {
decreaseCount() {
aleclarson / useSubscriber.jsx
Created Aug 16, 2019
useSubscriber: Baked-in hook that lets subscribers notify React when data goes stale
View useSubscriber.jsx
import {useSubscriber} from 'react'
const MyComponent = (props) => {
// Get the current value of an observable
const value = props.value.get()
// Subscribe to the observable in the render phase
useSubscriber(forceUpdate => {
// This code runs immediately, instead of acting like "useEffect"
const unsub = props.value.subscribe(() => {
aleclarson /
Last active Apr 10, 2020
react-spring v9

Changes in v9

  • Animated values are now instances of the SpringValue class, which gives users access to an imperative API for updating a single animated value.
  • The reset and immediate props can now be a key or array of keys, instead of only a function or boolean.
  • The next function passed to async to prop can now be passed any useSpring props, instead of only to values.
  • The useSpring hook now supports a deps array, for updating an animation only when certain values changed.
  • The useTransition hook was rewritten from scratch. (see #809)
  • The useTransition hook now has a ref prop.
  • The new cancel prop stops the current animation and prevents future animations. It can be a boolean, a function, a key, or an array of keys.
  • Delayed updates can be cancelled by the cancel prop or stop method.

<HotKey> for react-native-macos

There are two types of hotkeys: global and local.

  • Global hotkeys work even when the application is inactive.
  • Local hotkeys only work when the application is active.

The implementation for global hotkeys would be adapted from davedelong/DDHotKey.

The implementation for local hotkeys would use the RCTKeyCommands class that already exists.

You can’t perform that action at this time.