Skip to content

Instantly share code, notes, and snippets.

View shirakaba's full-sized avatar
💭
🧙‍♂️

Jamie Birch shirakaba

💭
🧙‍♂️
View GitHub Profile
@shirakaba
shirakaba / Swift_RN.md
Last active June 15, 2018 00:19
Using Swift in React Native

Bridging header

Purpose

While you can't import Objective-C headers directly in Swift files, you can import them all into a bridging header file, which will subsequently be exposed to your Swift environment throughout the project.

Thus, you should write into the bridging header the union of all headers you'll be referring to (e.g. due to invoking APIs or asserting types) in your Swift code.

For a React Native project, the fundamental headers you'll need come from the React static library. If you call upon any native modules, you'll need to import their headers, too.

@shirakaba
shirakaba / Promises.md
Last active June 15, 2018 09:33
Advanced Promise patterns

Passing resolve/reject handlers on to event listeners

import * as cp from "child_process";

function promisifiedSpawn(cmd, spawnArgsArray){
  return new Promise((resolve, reject) => {
    const cp = cp.spawn(cmd, spawnArgsArray);
    cp.on("exit", onExit.bind(this, resolve, reject));
 }
@shirakaba
shirakaba / main.swift
Created December 10, 2018 23:29
Entry file for a React Native Swift app
#if canImport(UIKit)
import UIKit
UIApplicationMain(
CommandLine.argc,
CommandLine.unsafeArgv,
NSStringFromClass(UIApplication.self),
NSStringFromClass(AppDelegate.self)
)
@shirakaba
shirakaba / DI, decorators, and mixins.md
Last active January 11, 2019 13:20
DI, decorators, and mixins notes for TypeScript

Dependency Injection

Dependency Injection (DI) is used to invert control in portions of a program. Here I focus on the concrete use-case of provisioning a class with a logger implementation that keeps a class-instance loggingInfo object so that any call to the logger will always include the info from loggingInfo (e.g. an id for a request that the class instance was constructed solely to handle) in its log messages.

In my implementations, I refer to global.wi, global.wd and other similarly cryptically-named methods; these stand for "Winston info-level log" and "Winston debug-level log", etc. (where Winston is the logging library I normally use). At the start of the program, it is assumed that one would register an implementation to these variables – typically a call to a Winston logger, but could equally be substituted for console.log.

Patterns

I wanted to investigate two key ways of augmenting existing classes, ultimately to achieve depen

@shirakaba
shirakaba / investigation.md
Last active March 2, 2019 19:36
NativeScript global-context native APIs

By executing the following code snippet in NS:IDE, we can see which native APIs have been exposed to JS, at least in the global context:

Object.keys(global).sort();

Thus, we can see that the following keys exist on the global object, most of which are iOS APIs. There is also precious little overlap with Node.js's global interface.

@shirakaba
shirakaba / react-nativescript-camera-plus.tsx
Created October 24, 2019 17:25
React wrapper for NativeScript Camera Plus
import * as console from "react-nativescript/dist/shared/Logger";
import * as React from "react";
import { PropsWithoutForwardedRef } from "react-nativescript/dist/shared/NativeScriptComponentTypings";
import { CameraPlus as NativeScriptCameraPlus, EventData } from "@nstudio/nativescript-camera-plus";
import { _ContentView, ContentViewComponentProps } from "react-nativescript/dist/components/ContentView";
import { updateListener } from "react-nativescript/dist/client/EventHandling";
import { Container, HostContext, Instance } from "react-nativescript/dist/shared/HostConfigTypes";
import { register } from "react-nativescript/dist/client/ElementRegistry";
const elementKey: string = "cameraPlus";
@shirakaba
shirakaba / PreviousNextView.tsx
Created January 9, 2020 10:24
nativescript-IQKeyboardManager: PreviousNextView
import * as console from "react-nativescript/dist/shared/Logger";
import * as React from "react";
import { PropsWithoutForwardedRef } from "react-nativescript/dist/shared/NativeScriptComponentTypings";
import { PreviousNextView as NativeScriptPreviousNextView, EventData } from "@nstudio/nativescript-camera-plus";
import { _ContentView, ContentViewComponentProps } from "react-nativescript/dist/components/ContentView";
import { updateListener } from "react-nativescript/dist/client/EventHandling";
import { Container, HostContext, Instance } from "react-nativescript/dist/shared/HostConfigTypes";
import { register } from "react-nativescript/dist/client/ElementRegistry";
const elementKey: string = "previousNextView";
@shirakaba
shirakaba / TextViewWithHint.tsx
Created January 9, 2020 10:26
nativescript-IQKeyboardManager: TextViewWithHint
import * as console from "react-nativescript/dist/shared/Logger";
import * as React from "react";
import { PropsWithoutForwardedRef } from "react-nativescript/dist/shared/NativeScriptComponentTypings";
import { TextViewWithHint as NativeScriptTextViewWithHint } from "@nativescript/core";
import { _TextView, TextViewComponentProps } from "react-nativescript/dist/components/TextView";
import { RNSFriendly } from "react-nativescript/dist/components/TextBase";
import { updateListener } from "react-nativescript/dist/client/EventHandling";
import { Container, HostContext, Instance } from "react-nativescript/dist/shared/HostConfigTypes";
import { register } from "react-nativescript/dist/client/ElementRegistry";
import { ContentViewProps, TextViewWithHintProps } from "react-nativescript/dist/shared/NativeScriptComponentTypings";
@shirakaba
shirakaba / Promises.md
Created January 27, 2020 14:54
Promise rejection behaviours

Error thrown within new Promise() block

new Promise((resolve, reject) => {
	throw new Error();
})
.then(() => {
	console.log("resolved!");
})
.catch((error) => {
export * from "./expo-nativescript-adapter.common";
export const NativeModulesProxy = {};
const provider = EXModuleRegistryProvider.new();
const moduleRegistry = provider.moduleRegistryForExperienceId(
"@sjchmiela/test"
);
const exportedModules = moduleRegistry.getAllExportedModules();
for (let i = 0; i < exportedModules.count; i++) {