From bf36cf8c71de8fda14f93748a64f6e836890687f Mon Sep 17 00:00:00 2001 From: Noah Phom Date: Sun, 21 Apr 2019 15:25:29 +0000 Subject: [PATCH] feat(icons): add MaterialIcons and Octicons --- .gitignore | 24 +++ .travis.yml | 22 +++ @types/react-native-vector-icons/index.d.ts | 19 ++ package.json | 9 +- src/App.tsx | 23 ++- src/examples/components/WelcomeText.tsx | 2 +- src/examples/features/welcome.ts | 12 +- src/index.tsx | 11 +- src/lib/context.tsx | 52 ----- src/lib/exports/Text/Text.tsx | 28 --- src/lib/exports/Text/condition.ts | 4 - src/lib/exports/Text/event.ts | 23 --- src/lib/exports/Text/hook.ts | 9 - src/lib/exports/Text/index.ts | 6 - src/lib/exports/Text/stream.ts | 47 ----- src/lib/exports/Text/trigger.ts | 35 ---- src/lib/exports/Touchable/Touchable.tsx | 58 ------ src/lib/exports/Touchable/condition.ts | 8 - src/lib/exports/Touchable/event.ts | 30 --- src/lib/exports/Touchable/hook.ts | 9 - src/lib/exports/Touchable/index.ts | 6 - src/lib/exports/Touchable/stream.ts | 86 -------- src/lib/exports/Touchable/trigger.ts | 35 ---- .../TouchableOpacity/TouchableOpacity.tsx | 41 ---- src/lib/exports/TouchableOpacity/condition.ts | 9 - src/lib/exports/TouchableOpacity/event.ts | 39 ---- src/lib/exports/TouchableOpacity/hook.ts | 12 -- src/lib/exports/TouchableOpacity/index.ts | 6 - src/lib/exports/TouchableOpacity/stream.ts | 87 --------- src/lib/exports/TouchableOpacity/trigger.ts | 37 ---- src/lib/exports/View/View.tsx | 28 --- src/lib/exports/View/condition.ts | 5 - src/lib/exports/View/event.ts | 21 -- src/lib/exports/View/hook.ts | 9 - src/lib/exports/View/index.ts | 6 - src/lib/exports/View/stream.ts | 35 ---- src/lib/exports/View/trigger.ts | 35 ---- src/lib/exports/index.ts | 4 - src/lib/functions/barn-bridge.ts | 21 -- src/lib/functions/common.ts | 14 -- src/lib/functions/index.ts | 2 - src/lib/functions/use-barn-state.ts | 20 -- src/lib/index.shared.ts | 184 ++++++++++++++++++ src/lib/index.ts | 36 +--- src/lib/index.web.ts | 24 +++ src/lib/models/base.ts | 8 - src/lib/models/index.ts | 2 - tsconfig.json | 3 +- tsconfig.lib.json | 2 +- yarn.lock | 128 ++++++++---- 50 files changed, 399 insertions(+), 977 deletions(-) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 @types/react-native-vector-icons/index.d.ts delete mode 100755 src/lib/context.tsx delete mode 100755 src/lib/exports/Text/Text.tsx delete mode 100755 src/lib/exports/Text/condition.ts delete mode 100755 src/lib/exports/Text/event.ts delete mode 100755 src/lib/exports/Text/hook.ts delete mode 100755 src/lib/exports/Text/index.ts delete mode 100755 src/lib/exports/Text/stream.ts delete mode 100755 src/lib/exports/Text/trigger.ts delete mode 100755 src/lib/exports/Touchable/Touchable.tsx delete mode 100755 src/lib/exports/Touchable/condition.ts delete mode 100755 src/lib/exports/Touchable/event.ts delete mode 100755 src/lib/exports/Touchable/hook.ts delete mode 100755 src/lib/exports/Touchable/index.ts delete mode 100755 src/lib/exports/Touchable/stream.ts delete mode 100755 src/lib/exports/Touchable/trigger.ts delete mode 100755 src/lib/exports/TouchableOpacity/TouchableOpacity.tsx delete mode 100755 src/lib/exports/TouchableOpacity/condition.ts delete mode 100755 src/lib/exports/TouchableOpacity/event.ts delete mode 100755 src/lib/exports/TouchableOpacity/hook.ts delete mode 100755 src/lib/exports/TouchableOpacity/index.ts delete mode 100755 src/lib/exports/TouchableOpacity/stream.ts delete mode 100755 src/lib/exports/TouchableOpacity/trigger.ts delete mode 100755 src/lib/exports/View/View.tsx delete mode 100755 src/lib/exports/View/condition.ts delete mode 100755 src/lib/exports/View/event.ts delete mode 100755 src/lib/exports/View/hook.ts delete mode 100755 src/lib/exports/View/index.ts delete mode 100755 src/lib/exports/View/stream.ts delete mode 100755 src/lib/exports/View/trigger.ts delete mode 100755 src/lib/exports/index.ts delete mode 100755 src/lib/functions/barn-bridge.ts delete mode 100755 src/lib/functions/common.ts delete mode 100755 src/lib/functions/index.ts delete mode 100755 src/lib/functions/use-barn-state.ts create mode 100644 src/lib/index.shared.ts mode change 100755 => 100644 src/lib/index.ts create mode 100644 src/lib/index.web.ts delete mode 100755 src/lib/models/base.ts delete mode 100755 src/lib/models/index.ts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..931232e --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build +/dist + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0c2f6f5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,22 @@ +language: node_js + +cache: + yarn: true + directories: + - node_modules + +notifications: + email: false + +node_js: + - node + +before_install: + - echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc + +script: + - yarn build + - yarn compile + +after_success: + - npx semantic-release \ No newline at end of file diff --git a/@types/react-native-vector-icons/index.d.ts b/@types/react-native-vector-icons/index.d.ts new file mode 100644 index 0000000..d9da53d --- /dev/null +++ b/@types/react-native-vector-icons/index.d.ts @@ -0,0 +1,19 @@ +declare module 'react-native-vector-icons' { + export * from 'react-native-vector-icons' +} + +declare module 'react-native-vector-icons/dist/MaterialIcons' { + +} + +declare module 'react-native-vector-icons/dist/Octicons' { + +} + +declare module 'react-native-vector-icons/Fonts/MaterialIcons.ttf' { + +} + +declare module 'react-native-vector-icons/Fonts/Octicons.ttf' { + +} \ No newline at end of file diff --git a/package.json b/package.json index 7489a8b..bbb0eb3 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bara-react-icons", "license": "MIT", - "description": "BaraJS for React creative", + "description": "BaraJS React vector icons for cross-platform!", "homepage": "https://barajs.dev", "repository": "https://github.com/barajs/bara-react-icons", "version": "0.0.0", @@ -16,19 +16,20 @@ "src/lib" ], "dependencies": { - "bara": "2.2.0", - "fbemitter": "2.1.1", + "bara": "2.3.1", + "bara-react": "2.0.1", + "react-native-vector-icons": "6.4.2", "react-native-web": "0.11.2" }, "devDependencies": { "@semantic-release/changelog": "3.0.2", "@semantic-release/git": "7.0.8", - "@types/fbemitter": "2.0.32", "@types/jest": "24.0.11", "@types/node": "11.13.5", "@types/react": "16.8.12", "@types/react-dom": "16.8.3", "@types/react-native": "0.57.42", + "@types/react-native-vector-icons": "6.4.0", "@typescript-eslint/typescript-estree": "1.6.0", "react": "16.8.6", "react-dom": "16.8.6", diff --git a/src/App.tsx b/src/App.tsx index 6d770d3..5fad569 100755 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,14 +1,10 @@ import { useBarn } from 'bara' +import { BaraProvider, Touchable, View, Text, TouchableOpacity } from 'bara-react' import React, { Component, ReactNode, useState, useEffect } from 'react' - import { StyleSheet } from 'react-native' -import { BaraProvider } from './lib/context' -import { Touchable } from './lib/exports/Touchable' -import { View } from './lib/exports/View' -import { Text } from './lib/exports/Text' -import { TouchableOpacity } from './lib/exports/TouchableOpacity' import { WelcomeText } from './examples/components/WelcomeText' +import { MaterialIcons as Icon, Octicons } from './lib' const styles = StyleSheet.create({ view: { @@ -35,15 +31,24 @@ const App = () => { return ( - Version: {version} + + Version: {version} - Welcome! + Material Icons + + + + - No Greet + Octicons + gear + + chevron-right + diff --git a/src/examples/components/WelcomeText.tsx b/src/examples/components/WelcomeText.tsx index 77f2edb..2ff201d 100755 --- a/src/examples/components/WelcomeText.tsx +++ b/src/examples/components/WelcomeText.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { Text, Touchable, useBarnState, View } from '../../lib' +import { Text, Touchable, useBarnState, View } from 'bara-react' export const WelcomeText = () => { const [message, setMessage] = useBarnState('welcome', 'Welcome to Bara App!') diff --git a/src/examples/features/welcome.ts b/src/examples/features/welcome.ts index 38133fe..6466918 100755 --- a/src/examples/features/welcome.ts +++ b/src/examples/features/welcome.ts @@ -1,4 +1,4 @@ -import { useInit, useBarn, useTimerElapsed } from 'bara' +import { useInit, useBarn, useTimerElapsed, setBarnState } from 'bara' import { nameOfTouchable, @@ -7,11 +7,11 @@ import { useTouchableOpacityPress, useTextPress, nameOfText, -} from '../../lib' +} from 'bara-react' -export function welcomeTrigger(setState: (key: string, value: any) => void) { +export function welcomeTrigger() { useInit(() => { - setState('welcome', `Loading...`) + setBarnState('welcome', `Loading...`) useBarn('welcome', newMessage => { }) }) @@ -21,7 +21,7 @@ export function welcomeTrigger(setState: (key: string, value: any) => void) { nameOf: nameOfTouchable('welcome-button'), }, ({ name }) => { - setState('welcome', `You (${name}) are already welcomed!`) + setBarnState('welcome', `You (${name}) are already welcomed!`) }, ) @@ -36,7 +36,7 @@ export function welcomeTrigger(setState: (key: string, value: any) => void) { ) useTimerElapsed(5, () => { - setState('welcome', `Who are you?`) + setBarnState('welcome', `Who are you?`) }) useBarn('welcome', newMessage => { diff --git a/src/index.tsx b/src/index.tsx index 8cf464b..e607c53 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,29 +1,28 @@ -import { register, useBarnStream } from 'bara' +import { register, useBarnStream, useInitStream } from 'bara' import App from './App' import './index.css' import { - mapBarnWithReact, useReactApp, useTextStream, useTouchableOpacityStream, useTouchableStream, useViewStream, -} from './lib' +} from 'bara-react' import { welcomeTrigger } from './examples/features/welcome' const BaraApp = () => { - const [setState] = useBarnStream({ + useInitStream() + useBarnStream({ version: '1.0.0', welcome: 'Welcome to Bara React App!', }) useReactApp({ name: 'bara-app', App }) - mapBarnWithReact(setState) useViewStream() useTouchableStream() useTouchableOpacityStream() useTextStream() - welcomeTrigger(setState) + welcomeTrigger() } const bara = register(BaraApp) diff --git a/src/lib/context.tsx b/src/lib/context.tsx deleted file mode 100755 index b63b9da..0000000 --- a/src/lib/context.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { BarnState } from 'bara' -import React, { ReactNode, useContext } from 'react' - -import { BarnContext, barnContext } from './functions/barn-bridge' - -import { BaraTouchableContext, touchableContext } from './exports/Touchable' -import { - BaraTouchableOpacityContext, - touchableOpacityContext, -} from './exports/TouchableOpacity' -import { BaraViewContext, viewContext } from './exports/View' -import { BaraTextContext, textContext } from './exports/Text' - -export interface BaraComponentsState { - touchable: BaraTouchableContext - touchableOpacity: BaraTouchableOpacityContext - view: BaraViewContext - text: BaraTextContext -} - -export interface BaraState { - components: BaraComponentsState - barn: BarnContext -} - -const baraState: BaraState = { - components: { - touchable: touchableContext, - touchableOpacity: touchableOpacityContext, - view: viewContext, - text: textContext, - }, - barn: barnContext, -} - -export const BaraProvider = (props: { children: ReactNode }) => { - return ( - - {props.children} - - ) -} - -const dummy = (...args: any[]) => undefined - -export const BaraContext = React.createContext(baraState) - -export const BaraConsumer = BaraContext.Consumer - -export const useBaraContext = (): BaraState => { - return useContext(BaraContext) -} diff --git a/src/lib/exports/Text/Text.tsx b/src/lib/exports/Text/Text.tsx deleted file mode 100755 index ef32c93..0000000 --- a/src/lib/exports/Text/Text.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import React, { ReactNode } from 'react' -import { - Text as TextOriginal, - TextProps as TextPropsOriginal, -} from 'react-native' - -import { useBaraContext } from '../../context' -import { BaraBaseComponentProps } from '../../models' - -export interface TextProps extends TextPropsOriginal, BaraBaseComponentProps { - children?: ReactNode -} - -export const Text = React.forwardRef( - ({ onPress: _onPress, ...props }: TextProps, ref: any) => { - const context = useBaraContext() - const onPress: typeof _onPress = e => { - context.components.text.onPress({ name, ...props }) - if (_onPress) { - _onPress(e) - } - } - - return - }, -) - -export type Text = TextOriginal diff --git a/src/lib/exports/Text/condition.ts b/src/lib/exports/Text/condition.ts deleted file mode 100755 index 30d0723..0000000 --- a/src/lib/exports/Text/condition.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { BaraReactText, TextPressEventFilter } from './event' - -export const nameOfText = (name: string) => (triggeringEvent: BaraReactText): boolean => - name ? name === triggeringEvent.name : true diff --git a/src/lib/exports/Text/event.ts b/src/lib/exports/Text/event.ts deleted file mode 100755 index b109a4b..0000000 --- a/src/lib/exports/Text/event.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { createEventType, useEvent } from 'bara' - -export interface BaraReactText { - name?: string - className?: string - ref?: any - id?: any -} - -export const ON_TEXT_PRESS = createEventType('ON_TEXT_PRESS') -export const ON_TEXT_LONG_PRESS = createEventType('ON_TEXT_LONG_PRESS') - -export type TextPressEventSource = ( - triggeringEvent: BaraReactText, -) => boolean | Promise - -export interface TextPressEventFilter { - nameOf?: TextPressEventSource - classOf?: TextPressEventSource -} - -export const useTextPressEvent = () => useEvent(ON_TEXT_PRESS) -export const useTextLongPressEvent = () => useEvent(ON_TEXT_LONG_PRESS) diff --git a/src/lib/exports/Text/hook.ts b/src/lib/exports/Text/hook.ts deleted file mode 100755 index 15e98f5..0000000 --- a/src/lib/exports/Text/hook.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TextPressEventFilter } from './event' -import { TextPressCallback, useTextPressTrigger } from './trigger' - -export function useTextPress( - eventFilter: TextPressEventFilter, - callback: TextPressCallback, -) { - return useTextPressTrigger(eventFilter, callback) -} diff --git a/src/lib/exports/Text/index.ts b/src/lib/exports/Text/index.ts deleted file mode 100755 index f6bcc40..0000000 --- a/src/lib/exports/Text/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './event' -export * from './condition' -export * from './hook' -export * from './stream' -export * from './Text' -export * from './trigger' diff --git a/src/lib/exports/Text/stream.ts b/src/lib/exports/Text/stream.ts deleted file mode 100755 index ee0e63b..0000000 --- a/src/lib/exports/Text/stream.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { useStream } from 'bara' -import { EventEmitter, EventSubscription } from 'fbemitter' - -import { BaraReactText, ON_TEXT_PRESS, ON_TEXT_LONG_PRESS } from './event' - -export interface BaraTextContext { - onPress: (data: BaraReactText) => void - onLongPress: (data: BaraReactText) => void -} - -const emitter = new EventEmitter() - -export const textContext: BaraTextContext = { - onPress: data => { - emitter.emit(ON_TEXT_PRESS(), data) - }, - onLongPress: data => { - emitter.emit(ON_TEXT_LONG_PRESS(), data) - }, -} - -export function useTextStream() { - return useStream(({ setName, emit, addEventTypes }) => { - setName('dev.barajs.react.text') - addEventTypes([ON_TEXT_PRESS, ON_TEXT_LONG_PRESS]) - - const onPressListener = emitter.addListener( - ON_TEXT_PRESS(), - (data: BaraReactText) => { - emit(ON_TEXT_PRESS, data) - }, - ) - - const onLongPressListener = emitter.addListener( - ON_TEXT_LONG_PRESS(), - (data: BaraReactText) => { - emit(ON_TEXT_LONG_PRESS, data) - }, - ) - - return () => { - onPressListener.remove() - onLongPressListener.remove() - emitter.removeAllListeners() - } - }) -} diff --git a/src/lib/exports/Text/trigger.ts b/src/lib/exports/Text/trigger.ts deleted file mode 100755 index 161af1d..0000000 --- a/src/lib/exports/Text/trigger.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { useAction, useCondition, useEvent, useTrigger } from 'bara' -import { - BaraReactText, - TextPressEventFilter, - useTextPressEvent, -} from './event' - -export type TextPressCallback = (textData: BaraReactText) => void - -export const useTextPressTrigger = ( - eventFilter: TextPressEventFilter, - callback: TextPressCallback, -) => { - return useTrigger(() => { - const event = useTextPressEvent() - const condition = useCondition( - (triggeringEvent: BaraReactText | undefined) => { - let flag = true - flag = - flag && - ((eventFilter.nameOf - ? eventFilter.nameOf(triggeringEvent!) - : flag) as boolean) - flag = - flag && - ((eventFilter.classOf - ? eventFilter.classOf(triggeringEvent!) - : flag) as boolean) - return flag - }, - ) - const action = useAction(callback) - return { event, condition, action } - }) -} diff --git a/src/lib/exports/Touchable/Touchable.tsx b/src/lib/exports/Touchable/Touchable.tsx deleted file mode 100755 index 4a507d3..0000000 --- a/src/lib/exports/Touchable/Touchable.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import React, { ReactNode } from 'react' -import { - TouchableOpacity, - TouchableOpacityProps, - TouchableWithoutFeedbackProps, -} from 'react-native' - -import { useBaraContext } from '../../context' -import { BaraBaseComponentProps, Omit } from '../../models' - -export interface TouchableBaseProps - extends BaraBaseComponentProps, - TouchableOpacityProps, - TouchableWithoutFeedbackProps { - TouchableComponent: any - children?: ReactNode -} - -export interface TouchableProps - extends Omit { - TouchableComponent?: TouchableBaseProps['TouchableComponent'] -} - -export const TouchableBase = React.forwardRef( - ( - { - TouchableComponent, - onPress: _onPress, - name, - ...props - }: TouchableBaseProps, - ref: any, - ) => { - const context = useBaraContext() - const onPress: typeof _onPress = e => { - context.components.touchable.onPress({ name, ...props }) - if (_onPress) { - _onPress(e) - } - } - return - }, -) - -export const Touchable = React.forwardRef( - (props: TouchableProps, ref: any) => { - return ( - - ) - }, -) - -export type Touchable = TouchableOpacity diff --git a/src/lib/exports/Touchable/condition.ts b/src/lib/exports/Touchable/condition.ts deleted file mode 100755 index 9fad8e0..0000000 --- a/src/lib/exports/Touchable/condition.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { BaraReactTouchable, TouchableEventFilter } from './event' - -export const nameOfTouchable = (name: string) => (triggeringEvent: BaraReactTouchable): boolean => - name ? name === triggeringEvent.name : true - -export const classOfTouchable = (className: string) => ( - triggeringEvent: BaraReactTouchable, -): boolean => (className ? className === triggeringEvent.className : true) diff --git a/src/lib/exports/Touchable/event.ts b/src/lib/exports/Touchable/event.ts deleted file mode 100755 index 97b99b8..0000000 --- a/src/lib/exports/Touchable/event.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { createEventType, useEvent } from 'bara' - -export interface BaraReactTouchable { - name?: string - className?: string - ref?: any - id?: string -} - -export const ON_TOUCHABLE_PRESS = createEventType('ON_TOUCHABLE_PRESSED') -export const ON_TOUCHABLE_PRESS_IN = createEventType('ON_TOUCHABLE_PRESS_IN') -export const ON_TOUCHABLE_PRESS_OUT = createEventType('ON_TOUCHABLE_PRESS_OUT') -export const ON_TOUCHABLE_LONG_PRESS = createEventType( - 'ON_TOUCHABLE_LONG_PRESS', -) - -export type TouchableEventSource = ( - triggeringEvent: BaraReactTouchable, -) => boolean | Promise - -export interface TouchableEventFilter { - nameOf?: TouchableEventSource - classOf?: TouchableEventSource -} - -export const useTouchablePressEvent = () => useEvent(ON_TOUCHABLE_PRESS) -export const useTouchablePressInEvent = () => useEvent(ON_TOUCHABLE_PRESS_IN) -export const useTouchablePressOutEvent = () => useEvent(ON_TOUCHABLE_PRESS_OUT) -export const useTouchableLongPressEvent = () => - useEvent(ON_TOUCHABLE_LONG_PRESS) diff --git a/src/lib/exports/Touchable/hook.ts b/src/lib/exports/Touchable/hook.ts deleted file mode 100755 index 9614c88..0000000 --- a/src/lib/exports/Touchable/hook.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TouchableEventFilter } from './event' -import { TouchablePressCallback, useTouchablePressTrigger } from './trigger' - -export function useTouchablePress( - eventFilter: TouchableEventFilter, - callback: TouchablePressCallback, -) { - return useTouchablePressTrigger(eventFilter, callback) -} diff --git a/src/lib/exports/Touchable/index.ts b/src/lib/exports/Touchable/index.ts deleted file mode 100755 index 34d7f8a..0000000 --- a/src/lib/exports/Touchable/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './event' -export * from './condition' -export * from './hook' -export * from './stream' -export * from './Touchable' -export * from './trigger' diff --git a/src/lib/exports/Touchable/stream.ts b/src/lib/exports/Touchable/stream.ts deleted file mode 100755 index e1f2f40..0000000 --- a/src/lib/exports/Touchable/stream.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { useStream } from 'bara' -import { EventEmitter, EventSubscription } from 'fbemitter' -import React from 'react' - -import { - BaraReactTouchable, - ON_TOUCHABLE_LONG_PRESS, - ON_TOUCHABLE_PRESS, - ON_TOUCHABLE_PRESS_IN, - ON_TOUCHABLE_PRESS_OUT, -} from './event' - -export interface BaraTouchableContext { - onPress: (data: BaraReactTouchable) => void - onPressIn: (data: BaraReactTouchable) => void - onPressOut: (data: BaraReactTouchable) => void - onLongPress: (data: BaraReactTouchable) => void -} - -// Emitter handle the reference with React Component via Context API -const emitter = new EventEmitter() - -// Export and being consumed by any Touchable component -export const touchableContext: BaraTouchableContext = { - onPress: data => { - emitter.emit(ON_TOUCHABLE_PRESS(), data) - }, - onPressIn: data => { - emitter.emit(ON_TOUCHABLE_PRESS_IN(), data) - }, - onPressOut: data => { - emitter.emit(ON_TOUCHABLE_PRESS_OUT(), data) - }, - onLongPress: data => { - emitter.emit(ON_TOUCHABLE_LONG_PRESS(), data) - }, -} - -// BaraJS Stream Register -export function useTouchableStream() { - return useStream(({ setName, emit, addEventTypes }) => { - setName('dev.barajs.react.touchable') - addEventTypes([ - ON_TOUCHABLE_LONG_PRESS, - ON_TOUCHABLE_PRESS, - ON_TOUCHABLE_PRESS_IN, - ON_TOUCHABLE_PRESS_OUT, - ]) - - const onPressListener = emitter.addListener( - ON_TOUCHABLE_PRESS(), - (data: BaraReactTouchable) => { - emit(ON_TOUCHABLE_PRESS, data) - }, - ) - - const onPressInListener = emitter.addListener( - ON_TOUCHABLE_PRESS_IN(), - (data: BaraReactTouchable) => { - emit(ON_TOUCHABLE_PRESS_IN, data) - }, - ) - - const onPressOutListener = emitter.addListener( - ON_TOUCHABLE_PRESS_OUT(), - (data: BaraReactTouchable) => { - emit(ON_TOUCHABLE_PRESS_OUT, data) - }, - ) - - const onLongPressListener = emitter.addListener( - ON_TOUCHABLE_LONG_PRESS(), - (data: BaraReactTouchable) => { - emit(ON_TOUCHABLE_LONG_PRESS, data) - }, - ) - - return () => { - onPressListener.remove() - onPressInListener.remove() - onPressOutListener.remove() - onLongPressListener.remove() - emitter.removeAllListeners() - } - }) -} diff --git a/src/lib/exports/Touchable/trigger.ts b/src/lib/exports/Touchable/trigger.ts deleted file mode 100755 index 9236f79..0000000 --- a/src/lib/exports/Touchable/trigger.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { useAction, useCondition, useEvent, useTrigger } from 'bara' -import { - BaraReactTouchable, - TouchableEventFilter, - useTouchablePressEvent, -} from './event' - -export type TouchablePressCallback = (touchableData: BaraReactTouchable) => void - -export const useTouchablePressTrigger = ( - eventFilter: TouchableEventFilter, - callback: TouchablePressCallback, -) => { - return useTrigger(() => { - const event = useTouchablePressEvent() - const condition = useCondition( - (triggeringEvent: BaraReactTouchable | undefined) => { - let flag = true - flag = - flag && - ((eventFilter.nameOf - ? eventFilter.nameOf(triggeringEvent!) - : flag) as boolean) - flag = - flag && - ((eventFilter.classOf - ? eventFilter.classOf(triggeringEvent!) - : flag) as boolean) - return flag - }, - ) - const action = useAction(callback) - return { event, condition, action } - }) -} diff --git a/src/lib/exports/TouchableOpacity/TouchableOpacity.tsx b/src/lib/exports/TouchableOpacity/TouchableOpacity.tsx deleted file mode 100755 index 7c9f692..0000000 --- a/src/lib/exports/TouchableOpacity/TouchableOpacity.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import React from 'react' -import { TouchableOpacity as TouchableOpacityOriginal } from 'react-native' -import { useBaraContext } from '../../context' -import { BaraBaseComponentProps, Omit } from '../../models' -import { Touchable, TouchableProps } from '../Touchable' - -export interface TouchableOpacityProps - extends Omit { - TouchableComponent?: TouchableProps['TouchableComponent'] -} - -export const TouchableOpacity = React.forwardRef( - ( - { - TouchableComponent, - onPress: _onPress, - name, - ...props - }: TouchableOpacityProps, - ref: any, - ) => { - const context = useBaraContext() - const onPress: typeof _onPress = e => { - context.components.touchableOpacity.onPress({ name, ...props }) - if (_onPress) { - _onPress(e) - } - } - return ( - - ) - }, -) - -export type TouchableOpacity = TouchableOpacityOriginal diff --git a/src/lib/exports/TouchableOpacity/condition.ts b/src/lib/exports/TouchableOpacity/condition.ts deleted file mode 100755 index eedb09e..0000000 --- a/src/lib/exports/TouchableOpacity/condition.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { BaraReactTouchableOpacity, TouchableOpacityEventFilter } from './event' - -export const nameOfTouchableOpacity = (name: string) => ( - triggeringEvent: BaraReactTouchableOpacity, -): boolean => (name ? name === triggeringEvent.name : true) - -export const classOfTouchableOpacity = (className: string) => ( - triggeringEvent: BaraReactTouchableOpacity, -): boolean => (className ? className === triggeringEvent.className : true) diff --git a/src/lib/exports/TouchableOpacity/event.ts b/src/lib/exports/TouchableOpacity/event.ts deleted file mode 100755 index 132407f..0000000 --- a/src/lib/exports/TouchableOpacity/event.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { createEventType, useEvent } from 'bara' - -export interface BaraReactTouchableOpacity { - name?: string - className?: string - ref?: any - id?: string -} - -export const ON_TOUCHABLE_OPACITY_PRESS = createEventType( - 'ON_TOUCHABLE_OPACITY_PRESSED', -) -export const ON_TOUCHABLE_OPACITY_PRESS_IN = createEventType( - 'ON_TOUCHABLE_OPACITY_PRESS_IN', -) -export const ON_TOUCHABLE_OPACITY_PRESS_OUT = createEventType( - 'ON_TOUCHABLE_OPACITY_PRESS_OUT', -) -export const ON_TOUCHABLE_OPACITY_LONG_PRESS = createEventType( - 'ON_TOUCHABLE_OPACITY_LONG_PRESS', -) - -export type TouchableOpacityEventSource = ( - triggeringEvent: BaraReactTouchableOpacity, -) => boolean | Promise - -export interface TouchableOpacityEventFilter { - nameOf?: TouchableOpacityEventSource - classOf?: TouchableOpacityEventSource -} - -export const useTouchableOpacityPressEvent = () => - useEvent(ON_TOUCHABLE_OPACITY_PRESS) -export const useTouchableOpacityPressInEvent = () => - useEvent(ON_TOUCHABLE_OPACITY_PRESS_IN) -export const useTouchableOpacityPressOutEvent = () => - useEvent(ON_TOUCHABLE_OPACITY_PRESS_OUT) -export const useTouchableOpacityLongPressEvent = () => - useEvent(ON_TOUCHABLE_OPACITY_LONG_PRESS) diff --git a/src/lib/exports/TouchableOpacity/hook.ts b/src/lib/exports/TouchableOpacity/hook.ts deleted file mode 100755 index 9fdf9ca..0000000 --- a/src/lib/exports/TouchableOpacity/hook.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { TouchableOpacityEventFilter } from './event' -import { - TouchableOpacityPressCallback, - useTouchableOpacityPressTrigger, -} from './trigger' - -export function useTouchableOpacityPress( - eventFilter: TouchableOpacityEventFilter, - callback: TouchableOpacityPressCallback, -) { - return useTouchableOpacityPressTrigger(eventFilter, callback) -} diff --git a/src/lib/exports/TouchableOpacity/index.ts b/src/lib/exports/TouchableOpacity/index.ts deleted file mode 100755 index 9066bd5..0000000 --- a/src/lib/exports/TouchableOpacity/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './TouchableOpacity' -export * from './event' -export * from './condition' -export * from './hook' -export * from './stream' -export * from './trigger' diff --git a/src/lib/exports/TouchableOpacity/stream.ts b/src/lib/exports/TouchableOpacity/stream.ts deleted file mode 100755 index e7bb7d5..0000000 --- a/src/lib/exports/TouchableOpacity/stream.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { useStream } from 'bara' -import { EventEmitter } from 'fbemitter' - -import { - BaraReactTouchableOpacity, - ON_TOUCHABLE_OPACITY_LONG_PRESS, - ON_TOUCHABLE_OPACITY_PRESS, - ON_TOUCHABLE_OPACITY_PRESS_IN, - ON_TOUCHABLE_OPACITY_PRESS_OUT, -} from './event' - -export interface BaraTouchableOpacityContext { - onPress: (data: BaraReactTouchableOpacity) => void - onPressIn: (data: BaraReactTouchableOpacity) => void - onPressOut: (data: BaraReactTouchableOpacity) => void - onLongPress: (data: BaraReactTouchableOpacity) => void -} - -// Emitter handle the reference with React Component via Context API -const emitter = new EventEmitter() - -// Export and being consumed by any Touchable component -export const touchableOpacityContext: BaraTouchableOpacityContext = { - onPress: data => { - emitter.emit(ON_TOUCHABLE_OPACITY_PRESS(), data) - }, - onPressIn: data => { - emitter.emit(ON_TOUCHABLE_OPACITY_PRESS_IN(), data) - }, - onPressOut: data => { - emitter.emit(ON_TOUCHABLE_OPACITY_PRESS_OUT(), data) - }, - onLongPress: data => { - emitter.emit(ON_TOUCHABLE_OPACITY_LONG_PRESS(), data) - }, -} - -// BaraJS Stream Register -export function useTouchableOpacityStream() { - return useStream( - ({ setName, emit, addEventTypes }) => { - setName('dev.barajs.react.touchableOpacity') - addEventTypes([ - ON_TOUCHABLE_OPACITY_LONG_PRESS, - ON_TOUCHABLE_OPACITY_PRESS, - ON_TOUCHABLE_OPACITY_PRESS_IN, - ON_TOUCHABLE_OPACITY_PRESS_OUT, - ]) - - const onPressListener = emitter.addListener( - ON_TOUCHABLE_OPACITY_PRESS(), - (data: BaraReactTouchableOpacity) => { - emit(ON_TOUCHABLE_OPACITY_PRESS, data) - }, - ) - - const onPressInListener = emitter.addListener( - ON_TOUCHABLE_OPACITY_PRESS_IN(), - (data: BaraReactTouchableOpacity) => { - emit(ON_TOUCHABLE_OPACITY_PRESS_IN, data) - }, - ) - - const onPressOutListener = emitter.addListener( - ON_TOUCHABLE_OPACITY_PRESS_OUT(), - (data: BaraReactTouchableOpacity) => { - emit(ON_TOUCHABLE_OPACITY_PRESS_OUT, data) - }, - ) - - const onLongPressListener = emitter.addListener( - ON_TOUCHABLE_OPACITY_LONG_PRESS(), - (data: BaraReactTouchableOpacity) => { - emit(ON_TOUCHABLE_OPACITY_LONG_PRESS, data) - }, - ) - - return () => { - onPressListener.remove() - onPressInListener.remove() - onPressOutListener.remove() - onLongPressListener.remove() - emitter.removeAllListeners() - } - }, - ) -} diff --git a/src/lib/exports/TouchableOpacity/trigger.ts b/src/lib/exports/TouchableOpacity/trigger.ts deleted file mode 100755 index 624077c..0000000 --- a/src/lib/exports/TouchableOpacity/trigger.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { useAction, useCondition, useEvent, useTrigger } from 'bara' -import { - BaraReactTouchableOpacity, - TouchableOpacityEventFilter, - useTouchableOpacityPressEvent, -} from './event' - -export type TouchableOpacityPressCallback = ( - touchableData: BaraReactTouchableOpacity, -) => void - -export const useTouchableOpacityPressTrigger = ( - eventFilter: TouchableOpacityEventFilter, - callback: TouchableOpacityPressCallback, -) => { - return useTrigger(() => { - const event = useTouchableOpacityPressEvent() - const condition = useCondition( - (triggeringEvent: BaraReactTouchableOpacity | undefined) => { - let flag = true - flag = - flag && - ((eventFilter.nameOf - ? eventFilter.nameOf(triggeringEvent!) - : flag) as boolean) - flag = - flag && - ((eventFilter.classOf - ? eventFilter.classOf(triggeringEvent!) - : flag) as boolean) - return flag - }, - ) - const action = useAction(callback) - return { event, condition, action } - }) -} diff --git a/src/lib/exports/View/View.tsx b/src/lib/exports/View/View.tsx deleted file mode 100755 index 6422d6e..0000000 --- a/src/lib/exports/View/View.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import React, { ReactNode } from 'react' -import { - View as ViewOriginal, - ViewProps as ViewPropsOriginal, -} from 'react-native' - -import { useBaraContext } from '../../context' -import { BaraBaseComponentProps } from '../../models' - -export interface ViewProps extends ViewPropsOriginal, BaraBaseComponentProps { - children?: ReactNode -} - -export const View = React.forwardRef( - ({ onLayout: _onLayout, name, ...props }: ViewProps, ref: any) => { - const context = useBaraContext() - const onLayout: typeof _onLayout = e => { - context.components.view.onLayout({ name, ...props }) - if (_onLayout) { - _onLayout(e) - } - } - - return - }, -) - -export type View = ViewOriginal diff --git a/src/lib/exports/View/condition.ts b/src/lib/exports/View/condition.ts deleted file mode 100755 index 451bcce..0000000 --- a/src/lib/exports/View/condition.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { BaraReactView } from './event' - -export const nameOfView = (name: string) => ( - triggeringEvent: BaraReactView, -): boolean => (name ? name === triggeringEvent.name : true) diff --git a/src/lib/exports/View/event.ts b/src/lib/exports/View/event.ts deleted file mode 100755 index ed53123..0000000 --- a/src/lib/exports/View/event.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { createEventType, useEvent } from 'bara' - -export interface BaraReactView { - name?: string - className?: string - ref?: any - id?: any -} - -export const ON_VIEW_LAYOUT = createEventType('ON_VIEW_LAYOUT') - -export type ViewEventSource = ( - triggeringEvent: BaraReactView, -) => boolean | Promise - -export interface ViewEventFilter { - nameOf?: ViewEventSource - classOf?: ViewEventSource -} - -export const useViewLayoutEvent = () => useEvent(ON_VIEW_LAYOUT) diff --git a/src/lib/exports/View/hook.ts b/src/lib/exports/View/hook.ts deleted file mode 100755 index 7247584..0000000 --- a/src/lib/exports/View/hook.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { ViewEventFilter } from './event' -import { ViewLayoutCallback, useViewLayoutTrigger } from './trigger' - -export function useViewLayout( - eventFilter: ViewEventFilter, - callback: ViewLayoutCallback, -) { - return useViewLayoutTrigger(eventFilter, callback) -} diff --git a/src/lib/exports/View/index.ts b/src/lib/exports/View/index.ts deleted file mode 100755 index 4fc829e..0000000 --- a/src/lib/exports/View/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './event' -export * from './condition' -export * from './hook' -export * from './stream' -export * from './View' -export * from './trigger' diff --git a/src/lib/exports/View/stream.ts b/src/lib/exports/View/stream.ts deleted file mode 100755 index 84fb0d4..0000000 --- a/src/lib/exports/View/stream.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { useStream } from 'bara' -import { EventEmitter } from 'fbemitter' - -import { BaraReactView, ON_VIEW_LAYOUT } from './event' - -export interface BaraViewContext { - onLayout: (data: BaraReactView) => void -} - -const emitter = new EventEmitter() - -export const viewContext: BaraViewContext = { - onLayout: data => { - emitter.emit(ON_VIEW_LAYOUT({ name: '' }), data) - }, -} - -export function useViewStream() { - return useStream(({ setName, emit, addEventTypes }) => { - setName('dev.barajs.react.view') - addEventTypes([ON_VIEW_LAYOUT]) - - const onLayoutListener = emitter.addListener( - ON_VIEW_LAYOUT({ name: '' }), - (data: BaraReactView) => { - emit(ON_VIEW_LAYOUT, data) - }, - ) - - return () => { - onLayoutListener.remove() - emitter.removeAllListeners() - } - }) -} diff --git a/src/lib/exports/View/trigger.ts b/src/lib/exports/View/trigger.ts deleted file mode 100755 index c81f631..0000000 --- a/src/lib/exports/View/trigger.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { useAction, useCondition, useEvent, useTrigger } from 'bara' -import { - BaraReactView, - ViewEventFilter, - useViewLayoutEvent, -} from './event' - -export type ViewLayoutCallback = (viewData: BaraReactView) => void - -export const useViewLayoutTrigger = ( - eventFilter: ViewEventFilter, - callback: ViewLayoutCallback, -) => { - return useTrigger(() => { - const event = useViewLayoutEvent() - const condition = useCondition( - (triggeringEvent: BaraReactView | undefined) => { - let flag = true - flag = - flag && - ((eventFilter.nameOf - ? eventFilter.nameOf(triggeringEvent!) - : flag) as boolean) - flag = - flag && - ((eventFilter.classOf - ? eventFilter.classOf(triggeringEvent!) - : flag) as boolean) - return flag - }, - ) - const action = useAction(callback) - return { event, condition, action } - }) -} diff --git a/src/lib/exports/index.ts b/src/lib/exports/index.ts deleted file mode 100755 index 1d38ea0..0000000 --- a/src/lib/exports/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './Touchable' -export * from './TouchableOpacity' -export * from './View' -export * from './Text' diff --git a/src/lib/functions/barn-bridge.ts b/src/lib/functions/barn-bridge.ts deleted file mode 100755 index 3d99f1b..0000000 --- a/src/lib/functions/barn-bridge.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { useInit } from 'bara' -import { EventEmitter } from 'fbemitter' - -export interface BarnContext { - setState: (key: string, value: any) => void -} - -export const barnContext: BarnContext = { - setState: (key: string, value: any) => { - console.log('Old set state still not being patched!') - return - }, -} - -export const mapBarnWithReact = ( - setState: (key: string, value: any) => void, -) => { - useInit(() => { - barnContext.setState = setState - }) -} diff --git a/src/lib/functions/common.ts b/src/lib/functions/common.ts deleted file mode 100755 index 2411c9d..0000000 --- a/src/lib/functions/common.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { - BaraReactTouchable, - TouchableEventFilter, -} from '../exports/Touchable/event' - -export type ReactComponentTriggeringEvent = BaraReactTouchable - -export const nameOf = (name: string) => ( - triggeringEvent: ReactComponentTriggeringEvent, -): boolean => (name ? name === triggeringEvent.name : true) - -export const classOf = (className: string) => ( - triggeringEvent: ReactComponentTriggeringEvent, -): boolean => (className ? className === triggeringEvent.className : true) diff --git a/src/lib/functions/index.ts b/src/lib/functions/index.ts deleted file mode 100755 index d52f8e7..0000000 --- a/src/lib/functions/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './use-barn-state' -export * from './barn-bridge' \ No newline at end of file diff --git a/src/lib/functions/use-barn-state.ts b/src/lib/functions/use-barn-state.ts deleted file mode 100755 index ade7d94..0000000 --- a/src/lib/functions/use-barn-state.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { useBarn } from 'bara' -import { useState } from 'react' -import { useBaraContext } from '../context' - -export function useBarnState( - key: string, - initValue = '', -): [typeof initValue, (newState: typeof initValue) => void] { - const [data, setData] = useState(initValue) - const context = useBaraContext() - - const setStateProxy = (newState: any): void => { - context.barn.setState(key, newState) - } - - useBarn(key, newData => { - setData(newData) - }) - return [data, setStateProxy] -} diff --git a/src/lib/index.shared.ts b/src/lib/index.shared.ts new file mode 100644 index 0000000..79e09b3 --- /dev/null +++ b/src/lib/index.shared.ts @@ -0,0 +1,184 @@ +import { IconProps } from 'react-native-vector-icons/Icon' + +export type GitHubIcon = + | 'alert' + | 'archive' + | 'arrow-down' + | 'arrow-left' + | 'arrow-ref_type-down' + | 'arrow-right' + | 'arrow-small-left' + | 'arrow-small-right' + | 'arrow-small-up' + | 'arrow-up' + | 'beaker' + | 'bell' + | 'bold' + | 'book' + | 'bookmark' + | 'briefcase' + | 'broadcast' + | 'browser' + | 'bug' + | 'calendar' + | 'check' + | 'checklist' + | 'chevron-down' + | 'chevron-left' + | 'chevron-right' + | 'chevron-up' + | 'circle-slash' + | 'circuit-board' + | 'clippy' + | 'clock' + | 'cloud-download' + | 'cloud-upload' + | 'code' + | 'comment' + | 'comment-discussion' + | 'credit-card' + | 'dash' + | 'dashboard' + | 'database' + | 'desktop-download' + | 'device-camera' + | 'device-camera-video' + | 'device-desktop' + | 'device-mobile' + | 'diff' + | 'diff-added' + | 'diff-ignored' + | 'diff-modified' + | 'diff-removed' + | 'diff-renamed' + | 'ellipses' + | 'ellipsis' + | 'eye' + | 'file' + | 'file-binary' + | 'file-code' + | 'file-directory' + | 'file-media' + | 'file-pdf' + | 'file-submodule' + | 'file-symlink-directory' + | 'file-symlink-file' + | 'file-text' + | 'file-zip' + | 'flame' + | 'fold' + | 'gear' + | 'gift' + | 'gist' + | 'gist-secret' + | 'git-branch' + | 'git-commit' + | 'git-compare' + | 'git-merge' + | 'git-pull-request' + | 'globe' + | 'grabber' + | 'graph' + | 'heart' + | 'history' + | 'home' + | 'horizontal-rule' + | 'hubot' + | 'inbox' + | 'info' + | 'issue-closed' + | 'issue-opened' + | 'issue-reopened' + | 'italic' + | 'jersey' + | 'key' + | 'keyboard' + | 'law' + | 'light-bulb' + | 'link' + | 'link-external' + | 'list-ordered' + | 'list-unordered' + | 'location' + | 'lock' + | 'logo-gist' + | 'logo-github' + | 'mail' + | 'mail-read' + | 'mail-reply' + | 'mark-github' + | 'markdown' + | 'megaphone' + | 'mention' + | 'milestone' + | 'mirror' + | 'mortar-board' + | 'mute' + | 'no-newline' + | 'note' + | 'octoface' + | 'organization' + | 'package' + | 'paintcan' + | 'pencil' + | 'person' + | 'pin' + | 'plug' + | 'plus' + | 'plus-small' + | 'primitive-dot' + | 'primitive-square' + | 'project' + | 'pulse' + | 'question' + | 'quote' + | 'radio-tower' + | 'reply' + | 'repo' + | 'repo-clone' + | 'repo-force-push' + | 'repo-forked' + | 'repo-pull' + | 'repo-push' + | 'rocket' + | 'rss' + | 'ruby' + | 'screen-full' + | 'screen-normal' + | 'search' + | 'server' + | 'settings' + | 'shield' + | 'sign-in' + | 'sign-out' + | 'smiley' + | 'squirrel' + | 'star' + | 'stop' + | 'sync' + | 'tag' + | 'tasklist' + | 'telescope' + | 'terminal' + | 'text-size' + | 'three-bars' + | 'thumbsdown' + | 'thumbsup' + | 'tools' + | 'trashcan' + | 'triangle-down' + | 'triangle-left' + | 'triangle-right' + | 'triangle-up' + | 'unfold' + | 'unmute' + | 'unverified' + | 'verified' + | 'versions' + | 'watch' + | 'x' + | 'zap' + +export interface OcticonIconProps extends IconProps { + name: GitHubIcon +} \ No newline at end of file diff --git a/src/lib/index.ts b/src/lib/index.ts old mode 100755 new mode 100644 index 39c73e6..dea36b7 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,34 +1,6 @@ -import { register, useInit, useStream } from 'bara' -import React, { ComponentType } from 'react' +import MaterialIcons from 'react-native-vector-icons/MaterialIcons' +import Octicons from 'react-native-vector-icons/Octicons' -import { AppRegistry } from 'react-native' +export * from './index.shared' -const BaraApp = (AppComponent: ComponentType) => () => AppComponent - -export interface UseReactAppConfig { - name: string - App: ComponentType - isNative?: boolean - rootHTML?: string -} - -export const useReactApp = ({ - name, - App, - isNative = false, - rootHTML = 'root', -}: UseReactAppConfig) => { - useInit(() => { - AppRegistry.registerComponent(name, BaraApp(App)) - if (!isNative) { - AppRegistry.runApplication(name, { - rootTag: document.getElementById(rootHTML), - }) - } - }) -} - -export * from './exports' -export * from './functions' -export * from './models' -export * from './context' +export { MaterialIcons, Octicons } \ No newline at end of file diff --git a/src/lib/index.web.ts b/src/lib/index.web.ts new file mode 100644 index 0000000..bb34152 --- /dev/null +++ b/src/lib/index.web.ts @@ -0,0 +1,24 @@ +import MaterialIcons from 'react-native-vector-icons/dist/MaterialIcons' +import Octicons from 'react-native-vector-icons/dist/Octicons' +import MaterialIconFont from 'react-native-vector-icons/Fonts/MaterialIcons.ttf' +import OcticonsFont from 'react-native-vector-icons/Fonts/Octicons.ttf' + +export * from './index.shared' + +export { Octicons, MaterialIcons } + +const iconStyles = [ + `@font-face { src:url(${MaterialIconFont});font-family: MaterialIcons; }`, + `@font-face { src:url(${OcticonsFont});font-family: Octicons; }`, +].join('\n') + +const style = document.createElement('style') +style.type = 'text/css' + +if ((style as any).styleSheet) { + ;(style as any).styleSheet.cssText = iconStyles +} else { + style.appendChild(document.createTextNode(iconStyles)) +} + +if (document.head) document.head.appendChild(style) diff --git a/src/lib/models/base.ts b/src/lib/models/base.ts deleted file mode 100755 index 23342e5..0000000 --- a/src/lib/models/base.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface BaraBaseComponentProps { - data?: any - name?: string - className?: string - id?: string -} - -export type Omit = Pick> diff --git a/src/lib/models/index.ts b/src/lib/models/index.ts deleted file mode 100755 index 4197d56..0000000 --- a/src/lib/models/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './base' - diff --git a/tsconfig.json b/tsconfig.json index b6f3f3e..034208e 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,8 +18,7 @@ "isolatedModules" : true, "noEmit": true, "jsx": "preserve", - "isolatedModules": true, - "typeRoots": [ "./@types", "./node_modules/@types" ] + "typeRoots": [ "@types", "node_modules/@types" ] }, "include": [ "src/*" diff --git a/tsconfig.lib.json b/tsconfig.lib.json index 43ddba7..52c67f3 100755 --- a/tsconfig.lib.json +++ b/tsconfig.lib.json @@ -21,7 +21,7 @@ "declaration": true, "rootDir": "src/lib", "outDir": "dist", - "typeRoots": [ "./@types", "./node_modules/@types" ] + "typeRoots": [ "@types", "node_modules/@types" ] }, "include": [ "src/lib" ] } diff --git a/yarn.lock b/yarn.lock index 0cd500b..75fa1d7 100755 --- a/yarn.lock +++ b/yarn.lock @@ -880,27 +880,26 @@ lodash "^4.17.11" to-fast-properties "^2.0.0" -"@bara/barn@^2.2.0": - version "2.2.0" - resolved "https://registry.yarnpkg.com/@bara/barn/-/barn-2.2.0.tgz#c9a230422e54ea18413deee6a10ca50f378a694c" - integrity sha512-I4WdWgZhZB17ppsISM2kRze3iHZklh0JRPT1+v83ob/D2oXpGQO9f2lUEhvcPGBByzB7VU5rqFIrm9XszP0oDg== +"@bara/barn@^2.3.1": + version "2.3.1" + resolved "https://registry.yarnpkg.com/@bara/barn/-/barn-2.3.1.tgz#74af0cac66534fd881cc4e31e5ad8d7011bb017c" + integrity sha512-0zS72TLvaprjHpOrj8O6f91lPB52qIoOVee3Zu+BZFdU2wkWCcgJf/Ag33txsfHRcg6eIi2h5Pbcv+aSa0C0TQ== dependencies: - "@bara/basics" "^2.2.0" - "@bara/core" "^2.2.0" + "@bara/basics" "^2.3.1" + "@bara/core" "^2.3.1" dot-prop "5.0.0" - xstream "11.10.0" -"@bara/basics@^2.2.0": - version "2.2.0" - resolved "https://registry.yarnpkg.com/@bara/basics/-/basics-2.2.0.tgz#a5171f92532703dbbff7e8f70bd8fc3fcde0087a" - integrity sha512-1fjbE8cYsdeV/l3HgVzgY2KUr4YhXGmAJzBjDc5Eg1B5Fdd/eNcVsYrruIaRYjGEMQll0xtgFh4IQVjAOnXhGA== +"@bara/basics@^2.3.1": + version "2.3.1" + resolved "https://registry.yarnpkg.com/@bara/basics/-/basics-2.3.1.tgz#27ec2f157f327af85b500a4ca31bdfb9f9a69334" + integrity sha512-QkSvXFcYwzlwRmv1r15jUVc73WK/bspe6A1geqJpRQJ66+04rq+5Vq0/QsOISSC4Y5rf+eewiVF6dVGDNMiXDA== dependencies: - "@bara/core" "^2.2.0" + "@bara/core" "^2.3.1" -"@bara/core@^2.2.0": - version "2.2.0" - resolved "https://registry.yarnpkg.com/@bara/core/-/core-2.2.0.tgz#bb1caa0927800137b51dd38e15b9fa9d44ca073f" - integrity sha512-qh3PG1TfIhSjUTLoxcwPh8Uh6DS6kuIdOWZhgg/qAvXzAxWdylXA8BkCyP6L7mDmReKdEGGvRjOGa03FUkVFqg== +"@bara/core@^2.3.1": + version "2.3.1" + resolved "https://registry.yarnpkg.com/@bara/core/-/core-2.3.1.tgz#5b1efb982b2ce59e1325a9ed33fa7ffcede75c40" + integrity sha512-8r+rwjHVWhMM9d4GTkNTM+OqHUGAVx/wUiOH+s68IiiBtnYTYlty/RQMKLE7uNcVHbPWvXArW9NLqQyPmQmAhA== dependencies: xstream "11.10.0" @@ -1189,11 +1188,6 @@ resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g== -"@types/fbemitter@2.0.32": - version "2.0.32" - resolved "https://registry.yarnpkg.com/@types/fbemitter/-/fbemitter-2.0.32.tgz#8ed204da0f54e9c8eaec31b1eec91e25132d082c" - integrity sha1-jtIE2g9U6cjq7DGx7skeJRMtCCw= - "@types/glob@^7.1.1": version "7.1.1" resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575" @@ -1247,6 +1241,22 @@ dependencies: "@types/react" "*" +"@types/react-native-vector-icons@6.4.0": + version "6.4.0" + resolved "https://registry.yarnpkg.com/@types/react-native-vector-icons/-/react-native-vector-icons-6.4.0.tgz#3ff6b29c8e831f11364c12801ae7966dab8dcbe0" + integrity sha512-UNRMIMbqeryNDQvZVZoPyqXIKLWmLRInhN5gDySxquJcZvWNW+1NSm4lXQlRdzC9Da3mSU1QEppoeI438f2JRw== + dependencies: + "@types/react" "*" + "@types/react-native" "*" + +"@types/react-native@*": + version "0.57.47" + resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.57.47.tgz#e7b6285ffa445ba474e4fdad4f2e6eda62fb392a" + integrity sha512-XeRcyrhPOsYEBOvh2RlLajNFmiDRALwAKiHXqPEEbYWzyJTKz095Cs/coHbUHQnDcKVmib4uHmrDAOK1q0PkmA== + dependencies: + "@types/prop-types" "*" + "@types/react" "*" + "@types/react-native@0.57.42": version "0.57.42" resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.57.42.tgz#06ad92cd1378146402b7667de13cb7b935d194d6" @@ -2160,14 +2170,22 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= -bara@2.2.0: - version "2.2.0" - resolved "https://registry.yarnpkg.com/bara/-/bara-2.2.0.tgz#dd4e57cdfcac915edea25de882827c5294a9c026" - integrity sha512-hbYuedzXGp03xpRfxdBg7sHHpBJaFisB0zuW6UKflqigRIoo1Yjj0IJo/F048WlWyWyMUPbmJh6HvrHkPlYd5Q== +bara-react@2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/bara-react/-/bara-react-2.0.1.tgz#97f2664001c41138da1e29a2c174223984944a2a" + integrity sha512-CFUpGwUmgWtsFZ5moU/IvYhZHklF+CiTy8AiSlUbDUKZMT+Q65IZ9P4JfuBM6CZYzWsl1GfaXCWGtxg/lmlBxA== dependencies: - "@bara/barn" "^2.2.0" - "@bara/basics" "^2.2.0" - "@bara/core" "^2.2.0" + bara "2.3.1" + react-native-web "0.11.2" + +bara@2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/bara/-/bara-2.3.1.tgz#736a827ca5c3f9966a244face477f8d98f490788" + integrity sha512-oF9mY8D11JHy/AE+dISVZbX9Us+ueYz38plolLUOuKLT4loa52Ov5Gw4xqfncpMcF/amWyVLwNE3pCCT6A9Rdg== + dependencies: + "@bara/barn" "^2.3.1" + "@bara/basics" "^2.3.1" + "@bara/core" "^2.3.1" base64-js@^1.0.2: version "1.3.0" @@ -4645,19 +4663,12 @@ fb-watchman@^2.0.0: dependencies: bser "^2.0.0" -fbemitter@2.1.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/fbemitter/-/fbemitter-2.1.1.tgz#523e14fdaf5248805bb02f62efc33be703f51865" - integrity sha1-Uj4U/a9SSIBbsC9i78M75wP1GGU= - dependencies: - fbjs "^0.8.4" - fbjs-css-vars@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/fbjs-css-vars/-/fbjs-css-vars-1.0.2.tgz#216551136ae02fe255932c3ec8775f18e2c078b8" integrity sha512-b2XGFAFdWZWg0phtAWLHCk836A1Xann+I+Dgd3Gk64MHKZO44FfoD1KxyvbSh0qZsIoXQGGlVztIY+oitJPpRQ== -fbjs@^0.8.4, fbjs@^0.8.9: +fbjs@^0.8.9: version "0.8.17" resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.17.tgz#c4d598ead6949112653d6588b01a5cdcd9f90fdd" integrity sha1-xNWY6taUkRJlPWWIsBpc3Nn5D90= @@ -5054,7 +5065,7 @@ get-caller-file@^1.0.1: resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a" integrity sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w== -get-caller-file@^2.0.0: +get-caller-file@^2.0.0, get-caller-file@^2.0.1: version "2.0.5" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== @@ -7245,7 +7256,7 @@ lodash.without@~4.4.0: resolved "https://registry.yarnpkg.com/lodash.without/-/lodash.without-4.4.0.tgz#3cd4574a00b67bae373a94b748772640507b7aac" integrity sha1-PNRXSgC2e643OpS3SHcmQFB7eqw= -"lodash@>=3.5 <5", lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1: +"lodash@>=3.5 <5", lodash@^4.0.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1: version "4.17.11" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== @@ -8487,7 +8498,7 @@ os-locale@^2.0.0: lcid "^1.0.0" mem "^1.1.0" -os-locale@^3.0.0: +os-locale@^3.0.0, os-locale@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-3.1.0.tgz#a802a6ee17f24c10483ab9935719cef4ed16bf1a" integrity sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q== @@ -9901,6 +9912,15 @@ react-is@^16.8.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16" integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA== +react-native-vector-icons@6.4.2: + version "6.4.2" + resolved "https://registry.yarnpkg.com/react-native-vector-icons/-/react-native-vector-icons-6.4.2.tgz#ee0b097e783387544ed160a3192a437c097e551d" + integrity sha512-G7Y5HksOQkCanFWKJ+fjwP38XL8tQREOSnw7jrbq28AFrrv41YtafOF4uDSDS7HxMRXs17HeEzn24OzJb63iuA== + dependencies: + lodash "^4.0.0" + prop-types "^15.6.2" + yargs "^13.2.2" + react-native-web@0.11.2: version "0.11.2" resolved "https://registry.yarnpkg.com/react-native-web/-/react-native-web-0.11.2.tgz#f3550589347be1f402f0641fefca687ca64a1750" @@ -10413,6 +10433,11 @@ require-main-filename@^1.0.1: resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" integrity sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE= +require-main-filename@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" + integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== + requires-port@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" @@ -12677,6 +12702,14 @@ yargs-parser@^11.1.1: camelcase "^5.0.0" decamelize "^1.2.0" +yargs-parser@^13.0.0: + version "13.0.0" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.0.0.tgz#3fc44f3e76a8bdb1cc3602e860108602e5ccde8b" + integrity sha512-w2LXjoL8oRdRQN+hOyppuXs+V/fVAYtpcrRxZuF7Kt/Oc+Jr2uAcVntaUTNT6w5ihoWfFDpNY8CPx1QskxZ/pw== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + yargs-parser@^9.0.2: version "9.0.2" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-9.0.2.tgz#9ccf6a43460fe4ed40a9bb68f48d43b8a68cc077" @@ -12737,3 +12770,20 @@ yargs@^12.0.0: which-module "^2.0.0" y18n "^3.2.1 || ^4.0.0" yargs-parser "^11.1.1" + +yargs@^13.2.2: + version "13.2.2" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.2.2.tgz#0c101f580ae95cea7f39d927e7770e3fdc97f993" + integrity sha512-WyEoxgyTD3w5XRpAQNYUB9ycVH/PQrToaTXdYXRdOXvEy1l19br+VJsc0vcO8PTGg5ro/l/GY7F/JMEBmI0BxA== + dependencies: + cliui "^4.0.0" + find-up "^3.0.0" + get-caller-file "^2.0.1" + os-locale "^3.1.0" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^3.0.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^13.0.0"