Skip to content

Commit ce31538

Browse files
author
Alex Lavrov
committed
Make some chagnes
1 parent 08a13bf commit ce31538

File tree

7 files changed

+49
-40
lines changed

7 files changed

+49
-40
lines changed

components/Buttons.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { PureComponent } from 'react';
22
import Icon from '@expo/vector-icons/Ionicons'
33
import { StyleSheet, TouchableOpacity } from 'react-native';
4+
import { MAX_SWIPE_DISTANCE } from "../constants";
45

56
const styles = StyleSheet.create({
67
headerButton: {
@@ -9,20 +10,11 @@ const styles = StyleSheet.create({
910
justifyContent: 'center'
1011
},
1112

12-
removeButton: {
13-
width: 60,
13+
swipeButton: {
14+
width: MAX_SWIPE_DISTANCE,
1415
height: '100%',
1516
alignItems: 'center',
1617
justifyContent: 'center'
17-
},
18-
19-
saveButton: {
20-
width: 50,
21-
height: 50,
22-
borderRadius: 25,
23-
backgroundColor: '#f4511e',
24-
alignItems: 'center',
25-
justifyContent: 'center'
2618
}
2719
})
2820

@@ -81,7 +73,7 @@ export class RemoveButton extends PureComponent {
8173
render() {
8274
return (
8375
<IconButton
84-
style={styles.removeButton}
76+
style={styles.swipeButton}
8577
iconName="md-trash"
8678
color="red"
8779
onPress={this.props.onPress}

components/NoteList.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
33
import { Alert, View, SwipeableFlatList } from 'react-native';
44
import { NoteListItem } from './NoteListItem'
55
import { RemoveButton } from './Buttons'
6+
import { MAX_SWIPE_DISTANCE } from "../constants";
67

78
export class NoteList extends Component {
89
static propTypes = {
@@ -43,7 +44,7 @@ export class NoteList extends Component {
4344
data={notes}
4445
bounceFirstRowOnMount={false}
4546
keyExtractor={item => item.id}
46-
maxSwipeDistance={60}
47+
maxSwipeDistance={MAX_SWIPE_DISTANCE}
4748
renderQuickActions={this.renderDeleteButton}
4849
renderItem={this.renderItem}
4950
/>

components/NoteListItem.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types'
3-
import { StyleSheet, Image, Text, View, UIManager, findNodeHandle } from 'react-native';
3+
import { StyleSheet, Image, Text, View, Platform, ActionSheetIOS, UIManager, findNodeHandle } from 'react-native';
44
import { MoreButton } from './Buttons'
55

66
const styles = StyleSheet.create({
@@ -57,7 +57,7 @@ export class NoteListItem extends Component {
5757
onNavigateNote: PropTypes.func,
5858
}
5959

60-
onPressMenu = (e, index) => {
60+
onPressMenu = index => {
6161
const { note, onNavigateNote, onRemoveNote } = this.props
6262
switch (index) {
6363
case 0:
@@ -68,12 +68,13 @@ export class NoteListItem extends Component {
6868
}
6969

7070
onOpenMenu = () => {
71-
UIManager.showPopupMenu(
72-
findNodeHandle(this._buttonRef),
73-
[ 'Edit', 'Delete' ],
74-
(e) => console.error(e),
75-
this.onPressMenu
76-
)
71+
const button = findNodeHandle(this._buttonRef)
72+
const options = [ 'Edit', 'Delete' ]
73+
74+
Platform.select({
75+
ios: ActionSheetIOS.showActionSheetWithOptions(options, this.onPressMenu),
76+
android: UIManager.showPopupMenu(button, options, (e) => console.error(e), (e, i) => this.onPressMenu(i))
77+
})
7778
}
7879

7980
render() {

components/ProjectList.js

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
1-
import React, { Component } from 'react';
1+
import React, { PureComponent } from 'react';
22
import { StyleSheet, FlatList, TouchableOpacity, Text, View } from 'react-native';
33

44
const styles = StyleSheet.create({
55
project: {
66
backgroundColor: 'white',
7-
borderBottomWidth: StyleSheet.hairlineWidth,
8-
borderColor: 'gray',
97
paddingVertical: 30,
10-
paddingHorizontal: 15
8+
paddingHorizontal: 15,
9+
borderBottomWidth: StyleSheet.hairlineWidth,
10+
borderColor: 'gray'
1111
},
1212
name: {
1313
fontSize: 16
1414
}
1515
})
1616

17-
export class ProjectList extends Component {
17+
export class ProjectListItem extends PureComponent {
18+
onPressProject = () => {
19+
const { project, onPressProject } = this.props
20+
onPressProject(project)
21+
}
22+
23+
render() {
24+
return (
25+
<TouchableOpacity onPress={this.onPressProject}>
26+
<View style={styles.project}>
27+
<Text style={styles.name}>{this.props.project.name}</Text>
28+
</View>
29+
</TouchableOpacity>
30+
)
31+
}
32+
}
33+
34+
export class ProjectList extends PureComponent {
1835
renderItem = ({ item }) => (
19-
<TouchableOpacity onPress={() => this.props.onPressProject(item.id, item.name)}>
20-
<View style={styles.project} >
21-
<Text style={styles.name}>{item.name}</Text>
22-
</View>
23-
</TouchableOpacity>
36+
<ProjectListItem
37+
project={item}
38+
onPressProject={this.props.onPressProject}
39+
/>
2440
)
2541

2642
render() {
27-
const { projects } = this.props
2843
return (
2944
<FlatList
30-
data={projects}
45+
data={this.props.projects}
3146
keyExtractor={item => item.id}
3247
renderItem={this.renderItem}
3348
/>

components/ProjectListItem.js

Whitespace-only changes.

constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const MAX_SWIPE_DISTANCE = 60

containers/Projects.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react';
1+
import React, { PureComponent } from 'react';
22
import { ProjectList } from '../components/ProjectList'
33
import { AddButton } from '../components/Buttons'
44
import { connect } from 'react-redux'
@@ -12,6 +12,10 @@ export class Projects extends Component {
1212
)
1313
})
1414

15+
componentDidMount() {
16+
this.props.navigation.setParams({ onRightButtonPress: this.navigateNewProject })
17+
}
18+
1519
navigateNewProject = () => {
1620
this.props.navigation.navigate('Project')
1721
}
@@ -20,15 +24,10 @@ export class Projects extends Component {
2024
this.props.navigation.navigate('Project', { projectId, name })
2125
}
2226

23-
componentDidMount() {
24-
this.props.navigation.setParams({ onRightButtonPress: this.navigateNewProject })
25-
}
26-
2727
render() {
28-
const { projects } = this.props
2928
return (
3029
<ProjectList
31-
projects={projects}
30+
projects={this.props.projects}
3231
onPressProject={this.navigateExistingProject}
3332
/>
3433
)

0 commit comments

Comments
 (0)