Skip to content

Commit

Permalink
fix onEventPress
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangnm committed Jun 30, 2018
1 parent 0b10523 commit cd0e463
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class App extends Component<{}> {
events={events}
selectedDate={this.selectedDate}
numberOfDays={3}
onEventPress={() => Alert.alert('select')}
onEventPress={(event) => Alert.alert('eventId:' + event.id)}
headerStyle={styles.headerStyle}
formatDateHeader="MMM D"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/Event/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import styles from './Event.styles';
const Event = ({ event, onPress, style }) => {
return (
<TouchableOpacity
onPress={onPress}
onPress={() => onPress(event)}
style={[styles.item, style, {
backgroundColor: event.color,
}]}
Expand Down
7 changes: 3 additions & 4 deletions src/Events/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const TimeRow = () => {
};

class Events extends Component {
onEventPress = (item) => {
onEventPress = (event) => {
const { onEventPress } = this.props;
if (onEventPress) {
onEventPress(item.data);
onEventPress(event);
}
};

Expand Down Expand Up @@ -140,7 +140,6 @@ class Events extends Component {
events,
numberOfDays,
selectedDate,
onEventPress,
times,
} = this.props;
const sortedEvents = this.sortEventByDates(events);
Expand All @@ -164,7 +163,7 @@ class Events extends Component {
key={item.data.id}
event={item.data}
style={item.style}
onPress={onEventPress}
onPress={this.onEventPress}
/>
);
})}
Expand Down
12 changes: 9 additions & 3 deletions src/Swipeable/Swipeable.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ export default class Swipeable extends Component {
};

render() {
const { numberOfDays, headerStyle, formatDateHeader } = this.props;
const {
numberOfDays,
headerStyle,
formatDateHeader,
onEventPress,
events,
} = this.props;
const { currentMoment } = this.state;
const dates = this.prepareDates(currentMoment, numberOfDays);
return (
Expand Down Expand Up @@ -127,8 +133,8 @@ export default class Swipeable extends Component {
times={this.times}
selectedDate={date.toDate()}
numberOfDays={numberOfDays}
onEventPress={this.props.onEventPress}
events={this.props.events}
onEventPress={onEventPress}
events={events}
/>
</View>
);
Expand Down
10 changes: 2 additions & 8 deletions src/WeekView/WeekView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,21 @@ import Events from '../Events/Events';
import styles from './WeekView.styles';

class WeekView extends Component {
onEventPress = (item) => {
const { onEventPress } = this.props;
if (onEventPress) {
onEventPress(item.data);
}
};

render() {
const {
events,
selectedDate,
numberOfDays,
times,
onEventPress,
} = this.props;
return (
<View style={styles.container}>
<Events
times={times}
events={events}
numberOfDays={numberOfDays}
onEventPress={this.onEventPress}
onEventPress={onEventPress}
selectedDate={selectedDate}
/>
</View>
Expand Down

0 comments on commit cd0e463

Please sign in to comment.