-
Notifications
You must be signed in to change notification settings - Fork 957
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): autocomplete - add placement property
- Loading branch information
Showing
7 changed files
with
87 additions
and
5 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
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
71 changes: 71 additions & 0 deletions
71
src/showcases/components/autocomplete/autocompleteHandleKeyboard.component.tsx
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,71 @@ | ||
import React from 'react'; | ||
import { Keyboard, Platform, StyleSheet } from 'react-native'; | ||
import { Autocomplete, Layout } from '@ui-kitten/components'; | ||
|
||
const DATA = [ | ||
{ title: 'Star Wars' }, | ||
{ title: 'Back to the Future' }, | ||
{ title: 'The Matrix' }, | ||
{ title: 'Inception' }, | ||
{ title: 'Interstellar' }, | ||
]; | ||
|
||
const showEvent = Platform.select({ | ||
android: 'keyboardDidShow', | ||
default: 'keyboardWillShow', | ||
}); | ||
|
||
const hideEvent = Platform.select({ | ||
android: 'keyboardDidHide', | ||
default: 'keyboardWillHide', | ||
}); | ||
|
||
export const AutocompleteHandleKeyboardShowcase = () => { | ||
|
||
const [value, setValue] = React.useState(null); | ||
const [data, setData] = React.useState(DATA); | ||
const [placement, setPlacement] = React.useState('bottom'); | ||
|
||
React.useEffect(() => { | ||
const keyboardShowListener = Keyboard.addListener(showEvent, () => { | ||
setPlacement('top'); | ||
}); | ||
|
||
const keyboardHideListener = Keyboard.addListener(hideEvent, () => { | ||
setPlacement('bottom'); | ||
}); | ||
|
||
return () => { | ||
keyboardShowListener.remove(); | ||
keyboardHideListener.remove(); | ||
}; | ||
}); | ||
|
||
const onSelect = ({ title }) => { | ||
setValue(title); | ||
}; | ||
|
||
const onChangeText = (query) => { | ||
setValue(query); | ||
setData(DATA.filter(item => item.title.toLowerCase().includes(query.toLowerCase()))); | ||
}; | ||
|
||
return ( | ||
<Layout style={styles.container}> | ||
<Autocomplete | ||
placeholder='Place your Text' | ||
value={value} | ||
data={data} | ||
placement={placement} | ||
onChangeText={onChangeText} | ||
onSelect={onSelect} | ||
/> | ||
</Layout> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
minHeight: 228, | ||
}, | ||
}); |