Skip to content

Commit 6adbfe5

Browse files
committed
Replace Component with PureComponent, add prop types, stylesheets
1 parent 18cd440 commit 6adbfe5

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

components/NoteDetail.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export class NoteDetail extends PureComponent {
2626
return (
2727
<View style={styles.note}>
2828
<TextInput
29-
style={styles.noteText}
3029
multiline
30+
style={styles.noteText}
3131
value={noteText}
3232
placeholder="Type note text here ..."
3333
underlineColorAndroid="transparent"

components/NoteList.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import React, { Component } from 'react';
1+
import React, { PureComponent } from 'react';
22
import PropTypes from 'prop-types'
33
import { NoteType } from './propTypes'
4-
import { Alert, View, SwipeableFlatList } from 'react-native';
4+
import { Alert, View, SwipeableFlatList, StyleSheet } from 'react-native';
55
import { NoteListItem } from './NoteListItem'
66
import { RemoveButton } from './Buttons'
77
import { MAX_SWIPE_DISTANCE } from "../constants";
88

9-
export class NoteList extends Component {
9+
const styles = StyleSheet.create({
10+
quickActions: {
11+
flex: 1,
12+
alignItems: 'flex-end'
13+
}
14+
})
15+
16+
export class NoteList extends PureComponent {
1017
static propTypes = {
1118
notes: PropTypes.arrayOf(NoteType),
1219
onRemoveNote: PropTypes.func,
@@ -25,7 +32,7 @@ export class NoteList extends Component {
2532
}
2633

2734
renderQuickActions = ({ item }) => (
28-
<View style={{ flex: 1, alignItems: 'flex-end' }}>
35+
<View style={styles.quickActions}>
2936
<RemoveButton onPress={() => this.onRemoveNote(item.id)} />
3037
</View>
3138
)

components/NoteListItem.js

+2-2
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 PropTypes from 'prop-types'
33
import { NoteType } from './propTypes'
44
import {
@@ -55,7 +55,7 @@ const styles = StyleSheet.create({
5555
}
5656
})
5757

58-
export class NoteListItem extends Component {
58+
export class NoteListItem extends PureComponent {
5959
static propTypes = {
6060
note: NoteType,
6161
onRemoveNote: PropTypes.func,

components/ProjectNameInput.js

+11-4
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 PropTypes from 'prop-types'
33
import { View, TextInput, StyleSheet } from 'react-native';
44

@@ -15,17 +15,24 @@ const styles = StyleSheet.create({
1515
}
1616
})
1717

18-
export class ProjectNameInput extends Component {
18+
export class ProjectNameInput extends PureComponent {
19+
static propTypes = {
20+
onSubmitEditing: PropTypes.func
21+
}
22+
23+
onSubmitEditing = e => {
24+
this.props.onSubmitEditing(e.nativeEvent.text)
25+
}
26+
1927
render() {
20-
const { onSubmitEditing } = this.props
2128
return (
2229
<View style={styles.container}>
2330
<TextInput
2431
autoFocus
2532
placeholder="Type project name here ..."
2633
placeholderTextColor="gray"
2734
underlineColorAndroid="transparent"
28-
onSubmitEditing={e => onSubmitEditing(e.nativeEvent.text)} />
35+
onSubmitEditing={this.onSubmitEditing} />
2936
</View>
3037
)
3138
}

containers/Project.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ export class Project extends PureComponent {
4444
const { projectId, project } = this.props
4545

4646
if (!projectId || !project) {
47-
return (<ProjectNameInput onSubmitEditing={this.createProject} />)
47+
return (
48+
<ProjectNameInput
49+
onSubmitEditing={this.createProject}
50+
/>
51+
)
4852
}
4953

5054
return (
@@ -59,8 +63,8 @@ export class Project extends PureComponent {
5963

6064
const mapStateToProps = (state, ownProps) => {
6165
const projectId = ownProps.navigation.getParam('projectId', null)
62-
6366
let project = null
67+
6468
if (projectId) {
6569
project = state.projects.find(project => projectId === project.id)
6670
}

0 commit comments

Comments
 (0)