Skip to content

Commit

Permalink
feat: js implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Onolememen committed Mar 29, 2020
1 parent 1460e76 commit e292afa
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "lib/commonjs/index.js",
"module": "lib/module/index.js",
"types": "lib/typescript/src/index.d.ts",
"react-native": "src/index.tsx",
"react-native": "src/index.ts",
"files": [
"src",
"lib",
Expand Down
60 changes: 60 additions & 0 deletions src/Bubble.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react';
import { requireNativeComponent, Platform } from 'react-native';

const RNBubble = requireNativeComponent('RNBubbleSelectNodeView');

export interface BubbleNode {
text: string;
id: string;
}

export type BubbleProps = BubbleNode & {
color?: string;
radius?: number;
marginScale?: number;
fontName?: string;
fontSize?: number;
fontColor?: string;
fontStyle?: 'bold' | 'bold-italic' | 'normal';
lineHeight?: number;
};

const Bubble = ({
text,
color,
radius,
marginScale,
id,
fontName,
fontSize,
fontColor,
lineHeight,
fontStyle,
}: BubbleProps) => {
const props = Platform.select({
ios: {
text,
color,
radius,
marginScale,
id,
fontName,
fontSize,
fontColor,
lineHeight,
},
android: {
text,
color,
id,
fontName,
fontSize,
fontColor,
fontStyle,
},
});

return <RNBubble {...props} />;
};

export default Bubble;
63 changes: 63 additions & 0 deletions src/BubbleSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react';
import { BubbleNode, BubbleProps } from './Bubble';
import { NativeSyntheticEvent, requireNativeComponent } from 'react-native';

const RNBubbleSelect = requireNativeComponent('RNBubbleSelectView');

export type BubbleSelectProps = Omit<BubbleProps, 'text' | 'id'> & {
onSelect?: (bubble: BubbleNode) => void;
onDeselect?: (bubble: BubbleNode) => void;
bubbleSize?: number;
allowsMultipleSelection?: boolean;
children: React.ReactNode;
style?: object;
width?: number;
height?: number;
};

const BubbleSelect = ({
onSelect,
onDeselect,
style,
allowsMultipleSelection,
children,
bubbleSize,
width = 200,
height = 200,
...bubbleProps
}: BubbleSelectProps) => {
const defaultStyle = {
flex: 1,
width,
height,
};

const handleSelect = (event: NativeSyntheticEvent<BubbleNode>) => {
console.log(event);
if (onSelect) {
onSelect(event.nativeEvent);
}
};

const handleDeselect = (event: NativeSyntheticEvent<BubbleNode>) => {
if (onDeselect) {
onDeselect(event.nativeEvent);
}
};

return (
<RNBubbleSelect
style={[defaultStyle, style]}
allowsMultipleSelection={allowsMultipleSelection}
onSelect={handleSelect}
onDeselect={handleDeselect}
bubbleSize={bubbleSize}
>
{React.Children.map(children, (child: any) =>
React.cloneElement(child, bubbleProps)
)}
</RNBubbleSelect>
);
};

export default BubbleSelect;
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import BubbleSelect from './BubbleSelect';

export * from './Bubble';
export * from './BubbleSelect';

export { default as Bubble } from './Bubble';
export default BubbleSelect;
9 changes: 0 additions & 9 deletions src/index.tsx

This file was deleted.

0 comments on commit e292afa

Please sign in to comment.