Skip to content

Commit

Permalink
various fixes and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
renrizzolo committed Jan 11, 2018
1 parent 0a4a1d4 commit b4bde20
Show file tree
Hide file tree
Showing 7 changed files with 851 additions and 688 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"plugin:react/recommended"
],
"rules": {
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/require-default-props": [0],
"semi": ["error", "never"],
"no-underscore-dangle": ["error", { "allowAfterThis": true }]
"no-underscore-dangle": ["error", { "allowAfterThis": true }]
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ yarn-error.log*
node_modules/

# exampleapp
exampleapp/
android/
ios/
82 changes: 40 additions & 42 deletions exampleapp/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,45 @@ const fonts = {
}),
}

const styles = StyleSheet.create({
center: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
marginTop: 30,
},
container: {
paddingTop: 40,
paddingHorizontal: 20,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
color: '#333',
},
border: {
borderBottomWidth: 1,
borderBottomColor: '#dadada',
marginBottom: 20,
},
heading: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 5,
marginTop: 20,
},
label: {
fontWeight: 'bold',
},
switch: {
marginBottom: 20,
flexDirection: 'row',
alignItems: 'flex-end',
justifyContent: 'space-between',
},
})

const tintColor = '#174A87'

const Loading = props => (
Expand Down Expand Up @@ -272,11 +311,10 @@ export default class App extends Component {
fetchCategories = () => {
this.setState({ hasErrored: false })

fetch('https://www.mocky.io/v2/5a5573a22f00005c04beea49?mocky-delay=1500ms')
fetch('https://www.mocky.io/v2/5a5573a22f00005c04beea49?mocky-delay=500ms')
.then(response => response.json())
.then((responseJson) => {
this.setState({ cats: responseJson })
console.log(this.state.cats)
})
.catch((error) => {
this.setState({ hasErrored: true })
Expand Down Expand Up @@ -362,43 +400,3 @@ export default class App extends Component {
)
}
}

const styles = StyleSheet.create({
center: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
marginTop: 30,
},
container: {
paddingTop: 40,
paddingHorizontal: 20,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
color: '#333',
},
border: {
borderBottomWidth: 1,
borderBottomColor: '#dadada',
marginBottom: 0,
},
heading: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 5,
marginTop: 20,
},
label: {
fontWeight: 'bold',
},
switch: {
marginBottom: 20,
flexDirection: 'row',
alignItems: 'flex-end',
justifyContent: 'space-between',
},
})

170 changes: 170 additions & 0 deletions lib/components/RowItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import {
View,
TouchableOpacity,
Text,
} from 'react-native'
import Icon from 'react-native-vector-icons/MaterialIcons'

class RowItem extends Component {
shouldComponentUpdate(nextProps) {
if (nextProps.selectedItems !== this.props.selectedItems) {

if (this.props.selectedItems.includes(this.props.item[this.props.uniqueKey]) &&
!nextProps.selectedItems.includes(this.props.item[this.props.uniqueKey])) {
return true
}
if (!this.props.selectedItems.includes(this.props.item[this.props.uniqueKey]) &&
nextProps.selectedItems.includes(this.props.item[this.props.uniqueKey])) {
return true
}
}

return false
}

_itemSelected = (item) => {
const { uniqueKey, selectedItems } = this.props
return selectedItems.includes(item[uniqueKey])
}

_toggleItem = (item, hasChildren) => {
this.props._toggleItem(item, hasChildren)
}

_toggleDropDown = (item, parent) => {
this.props._toggleDropDown(item, parent)
this.forceUpdate()
}

_showSubCategoryDropDown = (id) => {
this.props._showSubCategoryDropDown(id)
}

_dropDownOrToggle = (item, parent) => {
const {
readOnlyHeadings,
showDropDowns,
uniqueKey,
subKey,
} = this.props

const hasChildren = item[subKey] && item[subKey].length ? true : false

if (readOnlyHeadings && item[subKey] && showDropDowns) {
this._toggleDropDown(item[uniqueKey])
} else if (readOnlyHeadings && parent) {
return
} else {
this._toggleItem(item, hasChildren)
}
}

render(){
const {
item,
styles,
selectedItems,
uniqueKey,
subKey,
showDropDowns,
colors,
readOnlyHeadings,
itemFontFamily,
selectedIconComponent,
highlightChildren,
dropDownToggleIconUpComponent,
dropDownToggleIconDownComponent,
showSubCategories,
} = this.props

const hasDropDown = item[subKey] && item[subKey].length > 0 && showDropDowns

return (
<View
key={item[uniqueKey]}
style={{
flexDirection: 'row',
flex: 1,
backgroundColor: colors.itemBackground,
}}
>
<TouchableOpacity
disabled={(readOnlyHeadings && !showDropDowns) || item.disabled}
onPress={() => this._dropDownOrToggle(item, true)}
style={[{
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
paddingVertical: 6,
}, styles.item, this._itemSelected(item) && styles.selectedItem]}
>
<Text
style={[{ color: colors.text }, itemFontFamily, styles.itemText]}
>
{item.name}
</Text>
{
this._itemSelected(item) ?
selectedIconComponent ?
selectedIconComponent
:
<Icon
name="check"
style={{
fontSize: 16,
color: colors.success,
paddingLeft: 10,
}}
/> :
null
}
</TouchableOpacity>
{hasDropDown &&
<TouchableOpacity
style={[{
alignItems: 'flex-end',
justifyContent: 'center',
paddingHorizontal: 10,
backgroundColor: 'transparent',
}, styles.toggleIcon]}
onPress={() => { this._toggleDropDown(item[uniqueKey]) }}
>
{ this._showSubCategoryDropDown(item[uniqueKey]) ?
<View>
{ dropDownToggleIconUpComponent ? dropDownToggleIconUpComponent
:
<Icon
name="keyboard-arrow-up"
size={22}
style={{
color: colors.primary,
}}
/>
}
</View>
:
<View>
{ dropDownToggleIconDownComponent ? dropDownToggleIconDownComponent
:
<Icon
name="keyboard-arrow-down"
size={22}
style={{
color: colors.primary,
}}
/>
}
</View>
}
</TouchableOpacity>
}
</View>
)
}
}


export default RowItem
Loading

0 comments on commit b4bde20

Please sign in to comment.