-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #723 from shoutem/release/5.2.0
Release/5.2.0
- Loading branch information
Showing
70 changed files
with
1,106 additions
and
718 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { useMemo } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connectStyle } from '@shoutem/theme'; | ||
import { Text } from '../Text'; | ||
import { TouchableOpacity } from '../TouchableOpacity'; | ||
import { categoryShape } from './shapes'; | ||
|
||
function Category({ category, style, isSelected, onPress }) { | ||
const textStyle = useMemo( | ||
() => [style.category, !isSelected && style.selectedCategory], | ||
|
||
[isSelected, style.category, style.selectedCategory], | ||
); | ||
|
||
function handlePress() { | ||
if (isSelected) { | ||
return; | ||
} | ||
|
||
if (onPress) { | ||
onPress(category); | ||
} | ||
} | ||
|
||
return ( | ||
<TouchableOpacity onPress={handlePress} style={style.container}> | ||
<Text style={textStyle}>{category.name}</Text> | ||
</TouchableOpacity> | ||
); | ||
} | ||
|
||
Category.propTypes = { | ||
category: categoryShape.isRequired, | ||
isSelected: PropTypes.bool, | ||
style: PropTypes.object, | ||
onPress: PropTypes.func, | ||
}; | ||
|
||
Category.defaultProps = { | ||
style: {}, | ||
isSelected: false, | ||
onPress: undefined, | ||
}; | ||
|
||
export default React.memo(connectStyle('shoutem.ui.Category')(Category)); |
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,62 @@ | ||
import React, { useCallback } from 'react'; | ||
import { FlatList } from 'react-native'; | ||
import _ from 'lodash'; | ||
import PropTypes from 'prop-types'; | ||
import { connectStyle } from '@shoutem/theme'; | ||
import { View } from '../View'; | ||
import Category from './Category'; | ||
import { categoryShape } from './shapes'; | ||
|
||
export function CategoryPicker({ | ||
categories, | ||
onCategorySelected, | ||
style, | ||
selectedCategory, | ||
}) { | ||
const renderItem = useCallback( | ||
({ item: category }) => ( | ||
<Category | ||
category={category} | ||
key={category.id} | ||
onPress={onCategorySelected} | ||
isSelected={selectedCategory.id === category.id} | ||
/> | ||
), | ||
[selectedCategory.id, onCategorySelected], | ||
); | ||
|
||
if (_.size(categories) < 2) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<View style={style.container}> | ||
<FlatList | ||
horizontal | ||
scrollToOverflowEnabled | ||
contentContainerStyle={style.listContainer} | ||
showsHorizontalScrollIndicator={false} | ||
data={categories} | ||
renderItem={renderItem} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
CategoryPicker.propTypes = { | ||
categories: PropTypes.arrayOf(categoryShape), | ||
selectedCategory: categoryShape, | ||
style: PropTypes.object, | ||
onCategorySelected: PropTypes.func, | ||
}; | ||
|
||
CategoryPicker.defaultProps = { | ||
categories: [], | ||
style: {}, | ||
selectedCategory: undefined, | ||
onCategorySelected: undefined, | ||
}; | ||
|
||
export default React.memo( | ||
connectStyle('shoutem.ui.CategoryPicker')(CategoryPicker), | ||
); |
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 @@ | ||
export { default as CategoryPicker } from './CategoryPicker'; |
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 PropTypes from 'prop-types'; | ||
|
||
export const categoryShape = PropTypes.shape({ | ||
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, | ||
name: PropTypes.string.isRequired, | ||
description: PropTypes.string, | ||
}); |
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.