-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/optional-search-clear-icon
- Loading branch information
Showing
16 changed files
with
302 additions
and
8 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,63 @@ | ||
--- | ||
sidebar_position: 13 | ||
title: Custom Buttons | ||
--- | ||
|
||
import preview1 from '../../../assets/img/custom-button-preview-1.png' | ||
import preview2 from '../../../assets/img/custom-button-preview-2.png' | ||
import preview3 from '../../../assets/img/custom-button-preview-3.png' | ||
|
||
:::info | ||
To preview app with this example, clone [**github repo**](https://github.com/TheWidlarzGroup/rn-emoji-keyboard.git) and run `yarn example ios` or `yarn example android`. | ||
::: | ||
|
||
### Usage | ||
|
||
We've introduced a custom button feature to provide you with the flexibility to add your unique functionality to our interface. | ||
|
||
The `customButtons` prop allows you to inject custom buttons into the `EmojiPicker` component, enabling additional functionalities or actions within the emoji picker interface. This flexible prop accepts an array of React elements, allowing for multiple custom buttons to be specified. | ||
|
||
To use the `customButtons` prop, pass an array of React components that you wish to render as buttons within the emoji picker. Each component must be assigned a unique key prop to help React identify which items have changed, are being added, or are removed. | ||
|
||
If search bar is enabled, custom buttons shows next to it. | ||
|
||
The `DeleteButton` is a pre-designed component that can be used within the `EmojiPicker` as part of the customButtons prop array. You can add `onPress` prop with a function that will be called when the DeleteButton is pressed. This allows you to define the specific action that should occur on press, such as deleting an emoji from the input field. | ||
. You can add any pressableProps you need to this custom component. | ||
|
||
```jsx | ||
import EmojiPicker from 'rn-emoji-keyboard' | ||
|
||
const ExampleComponent = () => { | ||
// ... | ||
|
||
return ( | ||
<EmojiPicker | ||
onEmojiSelected={handlePick} | ||
open={isModalOpen} | ||
onClose={() => setIsModalOpen(false)} | ||
enableSearchBar | ||
customButtons={[ | ||
<DeleteButton | ||
key="deleteButton" | ||
onPress={deleteLastEmoji} | ||
style={({ pressed }) => ({ | ||
backgroundColor: pressed ? '#000' : '#e1e1e1', | ||
padding: 10, | ||
borderRadius: 100, | ||
})} | ||
iconNormalColor="#000" | ||
iconActiveColor="#fff" | ||
/>, | ||
]} | ||
allowMultipleSelections | ||
categoryPosition="top" | ||
/> | ||
) | ||
} | ||
``` | ||
|
||
<div className="gallery"> | ||
<img src={preview1} alt="First Image" /> | ||
<img src={preview2} alt="Second Image" /> | ||
<img src={preview3} alt="Third Image" /> | ||
</div> |
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
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,53 @@ | ||
import { Button } from 'example/src/components/Button' | ||
import React from 'react' | ||
import { Results } from 'example/src/components/Results' | ||
import EmojiPicker, { type EmojiType } from 'rn-emoji-keyboard' | ||
import { DeleteButton } from '../../../src/components/DeleteButton' | ||
|
||
export default function () { | ||
const [result, setResult] = React.useState<string>() | ||
const [isModalOpen, setIsModalOpen] = React.useState<boolean>(false) | ||
|
||
const handlePick = (emoji: EmojiType) => { | ||
console.log(emoji) | ||
setResult(emoji.emoji) | ||
setIsModalOpen((prev) => !prev) | ||
} | ||
|
||
const deleteLastEmoji = () => { | ||
if (result) { | ||
let arrayFromString = Array.from(result) | ||
arrayFromString.pop() | ||
setResult(arrayFromString.join('')) | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<Results label={result} /> | ||
<Button onPress={() => setIsModalOpen(true)} label="Open" /> | ||
|
||
<EmojiPicker | ||
onEmojiSelected={handlePick} | ||
open={isModalOpen} | ||
onClose={() => setIsModalOpen(false)} | ||
enableSearchBar | ||
customButtons={[ | ||
<DeleteButton | ||
key="deleteButton" | ||
onPress={deleteLastEmoji} | ||
style={({ pressed }) => ({ | ||
backgroundColor: pressed ? '#000' : '#e1e1e1', | ||
padding: 10, | ||
borderRadius: 100, | ||
})} | ||
iconNormalColor="#000" | ||
iconActiveColor="#fff" | ||
/>, | ||
]} | ||
allowMultipleSelections | ||
categoryPosition="top" | ||
/> | ||
</> | ||
) | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,66 @@ | ||
import React from 'react' | ||
import { | ||
View, | ||
Pressable, | ||
StyleSheet, | ||
type StyleProp, | ||
type ViewStyle, | ||
type PressableProps, | ||
} from 'react-native' | ||
import { KeyboardContext } from '../contexts/KeyboardContext' | ||
import { Icon } from './Icon' | ||
|
||
type CustomButtonType = { | ||
containerStyle?: StyleProp<ViewStyle> | ||
iconNormalColor?: string | ||
iconActiveColor?: string | ||
} & PressableProps | ||
|
||
export const DeleteButton = ({ | ||
containerStyle, | ||
iconNormalColor, | ||
iconActiveColor, | ||
...pressableProps | ||
}: CustomButtonType) => { | ||
const { theme } = React.useContext(KeyboardContext) | ||
return ( | ||
<View style={[styles.buttonContainer, containerStyle]}> | ||
<Pressable | ||
style={({ pressed }) => [ | ||
{ | ||
backgroundColor: pressed | ||
? theme.customButton.backgroundPressed | ||
: theme.customButton.background, | ||
padding: 8, | ||
borderRadius: 100, | ||
}, | ||
styles.button, | ||
]} | ||
{...pressableProps} | ||
> | ||
{({ pressed }) => ( | ||
<Icon | ||
iconName="Backspace" | ||
isActive={pressed} | ||
normalColor={iconNormalColor || theme.customButton.icon} | ||
activeColor={iconActiveColor || theme.customButton.iconPressed} | ||
/> | ||
)} | ||
</Pressable> | ||
</View> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
buttonContainer: { | ||
marginTop: 16, | ||
marginLeft: 8, | ||
flexDirection: 'row', | ||
justifyContent: 'flex-end', | ||
alignItems: 'center', | ||
}, | ||
button: { | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}) |
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
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
Oops, something went wrong.