Skip to content

Instantly share code, notes, and snippets.

View jdmunro's full-sized avatar

James Munro jdmunro

View GitHub Profile
export default class LinearGradient extends React.PureComponent<Props> {
render() {
// See gist for full implementation
// https://bit.ly/2X2yJzL
// ...
}
}
module.exports = {
// ...
resolve: {
// ...
alias: {
"@datacamp/react-native-linear-gradient": path.resolve(
__dirname,
"./mocked_modules/react-native-linear-gradient"
)
}
@jdmunro
jdmunro / react-native-linear-gradient.web.js
Created February 14, 2019 11:03
react-native-linear-gradient.web.js
/* @flow */
// https://github.com/necolas/react-native-web/issues/298#issuecomment-292776647
import { View } from 'react-native'
import * as React from 'react'
import type { Style } from 'app/types'
type Point = {|
x: number,
y: number,
@jdmunro
jdmunro / selectOnPlatform.js
Created February 13, 2019 13:18
selectOnPlatform.js
/* @flow */
import { Platform } from 'react-native'
const PLATFORM_PREFERENCES = Object.freeze({
ios: ['ios', 'mobile'],
android: ['android', 'mobile'],
web: ['web'],
})
@jdmunro
jdmunro / example.js
Last active May 11, 2018 09:53
Safe react-native native module resolution
// Naive example: results in runtime error if native module not present in native binary
import {PushNotificationIOS} from 'react-native' // Same problem if you use require
if (PushNotificationIOS) { // Referencing this variable immediately throws a runtime exception
alert('We have the library')
}
// Solution: you can wrap in an exception handler
const safePushNotificationIOS = () => {
try {
### Keybase proof
I hereby claim:
* I am jdmunro on github.
* I am jdmunro (https://keybase.io/jdmunro) on keybase.
* I have a public key ASC8mRg8SLIbrIwkV5OEZ6D6b16VuPTHi_rFUeJEbV8xUgo
To claim this, I am signing this object:
import * as featureFlags from './featureFlags'
...
<View>
{featureFlags.MY_SCHEDULE ? <MyScheduleButton.../> : null}
{featureFlags.MY_MESSAGES ? <MyMessagesButton.../> : null}
{featureFlags.MY_ACCOUNT ? <MyAccountButton.../> : null}
</View>
export const MY_SCHEDULE = false
export const MY_MESSAGES = false
export const MY_ACCOUNT = true
describe('Meal Plan List', () => {
it('renders correctly', () => {
const week = immutable.Map({
week: 4,
year: 2017,
});
store.dispatch(importMeals(SAMPLE_MEALS));
store.dispatch(setVisibleWeek(week));
it('does not repeat meals within the same week if enough meals are available', () => {
const mealIds = ['1', '2', '3', '4', '5', '6', '7'];
const meals = immutable.fromJS({
[mealIds[0]]: {name: 'Spaghetti'},
[mealIds[1]]: {name: 'Fish and Chips'},
[mealIds[2]]: {name: 'Meat and Potato Pie'},
[mealIds[3]]: {name: 'Lasagne'},
[mealIds[4]]: {name: 'Fish Stew'},
[mealIds[5]]: {name: 'Toad in the Hole'},
[mealIds[6]]: {name: 'Pork Cutlets'},