-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jesse Onolememen
committed
Mar 29, 2020
1 parent
1460e76
commit e292afa
Showing
5 changed files
with
131 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file was deleted.
Oops, something went wrong.