Skip to content

Instantly share code, notes, and snippets.

View jdmunro's full-sized avatar

James Munro jdmunro

View GitHub Profile
export const MY_SCHEDULE = false
export const MY_MESSAGES = false
export const MY_ACCOUNT = true
import * as featureFlags from './featureFlags'
...
<View>
{featureFlags.MY_SCHEDULE ? <MyScheduleButton.../> : null}
{featureFlags.MY_MESSAGES ? <MyMessagesButton.../> : null}
{featureFlags.MY_ACCOUNT ? <MyAccountButton.../> : null}
</View>
### 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:
@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 {
@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 / 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,
module.exports = {
// ...
resolve: {
// ...
alias: {
"@datacamp/react-native-linear-gradient": path.resolve(
__dirname,
"./mocked_modules/react-native-linear-gradient"
)
}
export default class LinearGradient extends React.PureComponent<Props> {
render() {
// See gist for full implementation
// https://bit.ly/2X2yJzL
// ...
}
}
import * as React from "react";
const codePush = (App: React.Node) => App;
codePush.getUpdateMetaData = () => {
return Promise.resolve(null);
};
export default codePush;
const marginStyle = {
marginTop: Platform.OS === "android" ? 60 : 19,
marginBottom: Platform.OS === "android" ? 60 : 0
};