Skip to content

Instantly share code, notes, and snippets.

View orYoffe's full-sized avatar
🇺🇦
Stand with Ukraine

Or Yoffe orYoffe

🇺🇦
Stand with Ukraine
View GitHub Profile
@orYoffe
orYoffe / WebPicker.js
Created December 21, 2017 12:47
React Native Web starter app WebPicker Component
import React from 'react';
import { createElement } from 'react-native-web';
const Option = ({
label,
value,
}) => createElement('option', {
children: label,
value,
});
@orYoffe
orYoffe / switchSnapshots.js
Created December 21, 2017 12:51
React Native Web starter app switch snapshots script
/* eslint-disable no-console */
const path = require('path');
const fs = require('fs');
const fsx = require('fs-extra');
const glob = require('glob');
const getPlatformDirName = isNative => isNative ? '__native_snapshots__' : '__web_snapshots__';
const getOtherPlatformDirName = isNative => isNative ? '__web_snapshots__' : '__native_snapshots__';
const ensureFolder = dir => !fs.existsSync(dir) && fs.mkdirSync(dir);
@orYoffe
orYoffe / Button.test.js
Last active January 1, 2018 13:20
React Native Web starter app Button Component test
import { Platform } from 'react-native';
it('renders properly - ' + Platform.OS, () => { // <= 'ios' || 'web'
const mockFunc = jest.fn();
const tree = renderer.create(
<Button text={text} onClick={mockFunc} />
);
expect(tree.toJSON()).toMatchSnapshot();
});
@orYoffe
orYoffe / Button.test.js
Last active December 23, 2017 11:41
Button.test.js old
import { Platform } from 'react-native';
const mockFunc = jest.fn();
const tree = renderer.create(
<Button text={text} onClick={mockFunc} />
);
if (Platform.OS === 'web') {
it('renders properly on web', () => { // <= the name sets the title for the snapshot
expect(tree.toJSON()).toMatchSnapshot();
@orYoffe
orYoffe / NativePicker.js
Created December 23, 2017 09:41
React Native Web starter app NativePicker component
import React from 'react';
import { Picker } from 'react-native';
export const NativePicker = ({
style,
currentValue,
onChange,
options,
}) => (
<Picker
@orYoffe
orYoffe / Button.test.js
Last active January 1, 2018 13:19
Button.test.js functionality test
import React from 'react';
import { Platform, Text, TouchableHighlight, StyleSheet } from 'react-native';
import { shallow } from 'enzyme';
import Button from './Button';
const text = 'test button';
const styles = StyleSheet.create({
button: {
height: 20,
const HelloReact = () => (
<div>
<p>Hello React</p>
</div>
);
const HelloReactNative = () => (
<View>
<Text>Hello ReactNative</Text>
</View>
@orYoffe
orYoffe / common.js
Created December 28, 2018 13:48
How to tel which env you are on with react native and react native web
import { Platform } from 'react-native';
const isWeb = Platform.OS === 'web';
const isNative = !isWeb;
const isIos = Platform.OS === 'ios';
const isAndroid = Platform.OS === 'android';
const isDesktop = isWeb && typeof matchMedia !== 'undefined' && matchMedia('(min-width: 768px)').matches;
const isMobile = !isDesktop;
@orYoffe
orYoffe / removeBanner.js
Created August 7, 2019 16:52
a script to add a button that would remove blocking banners
let banner;
function removeBanner() {
banner = document.elementFromPoint(300, 300);
if (banner.offsetWidth > 600) {
banner.parentNode.removeChild(banner);
console.log('!!! removeBanner ------ removed');
} else {
console.log('!!! removeBanner ------ did not removed')
}
@orYoffe
orYoffe / jstates_simple_example.js
Last active July 23, 2020 15:29
jstates simple example
const createState = require("jstates");
const myState = createState({ counter: 0 });
function onUpdate(state) {
console.log("onUpdate: counter =", state.counter);
}
myState.subscribe(onUpdate);
myState.setState(state => ({ counter: ++state.counter }));