Skip to content

Commit

Permalink
Merge pull request #1 from lucasfeijo/dynamic-width
Browse files Browse the repository at this point in the history
Dynamic width
  • Loading branch information
lucasfeijo authored Jan 29, 2020
2 parents 8d00629 + c25b429 commit aac42f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
TouchableOpacity,
TextInput,
Platform,
Dimensions,
ActivityIndicator,
AsyncStorage,
FlatList
Expand Down Expand Up @@ -65,10 +64,9 @@ const filteredEmojis = emoji.filter(e => !e["obsoleted_by"]);
const emojiByCategory = category =>
filteredEmojis.filter(e => e.category === category);
const sortEmoji = list => list.sort((a, b) => a.sort_order - b.sort_order);
const { width } = Dimensions.get("screen");
const categoryKeys = Object.keys(Categories);

const TabBar = ({ theme, activeCategory, onPress }) => {
const TabBar = ({ theme, activeCategory, onPress, width }) => {
const tabSize = width / categoryKeys.length;

return categoryKeys.map(c => {
Expand Down Expand Up @@ -126,7 +124,8 @@ export default class EmojiSelector extends Component {
isReady: false,
history: [],
emojiList: null,
colSize: 0
colSize: 0,
width: 0
};

//
Expand Down Expand Up @@ -243,12 +242,20 @@ export default class EmojiSelector extends Component {
this.setState(
{
emojiList,
colSize: Math.floor(width / this.props.columns)
colSize: Math.floor(this.state.width / this.props.columns)
},
cb
);
}

handleLayout = ({ nativeEvent: { layout } }) => {
this.setState({ width: layout.width }, () => {
this.prerenderEmojis(() => {
this.setState({ isReady: true });
});
})
};

//
// LIFECYCLE METHODS
//
Expand All @@ -259,14 +266,6 @@ export default class EmojiSelector extends Component {
if (showHistory) {
this.loadHistoryAsync();
}

this.prerenderEmojis(() => {
this.setState({ isReady: true });
});
}

handleLayout = ({ nativeEvent: { layout: { width: layoutWidth } } }) => {
this.setState({ colSize: Math.floor(layoutWidth / this.props.columns) });
}

render() {
Expand Down Expand Up @@ -308,6 +307,7 @@ export default class EmojiSelector extends Component {
activeCategory={category}
onPress={this.handleTabSelect}
theme={theme}
width={this.state.width}
/>
)}
</View>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-emoji-selector",
"version": "0.1.7",
"version": "0.1.8",
"description": "A react native emoji selector",
"main": "index.js",
"scripts": {
Expand All @@ -19,6 +19,6 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/arronhunt/react-native-emoji-selector.git"
"url": "git+https://github.com/lucasfeijo/react-native-emoji-selector.git"
}
}

0 comments on commit aac42f1

Please sign in to comment.