Merge remote-tracking branch 'origin/master'

This commit is contained in:
mx1700 2019-07-15 22:11:27 +08:00
commit da7ff8050a
16 changed files with 120 additions and 34 deletions

View file

@ -114,7 +114,7 @@ const localStyle = StyleSheet.create({
moreIcon: { moreIcon: {
position: 'absolute', position: 'absolute',
bottom: 0, bottom: 0,
right: 10, right: 15,
paddingHorizontal: 12, paddingHorizontal: 12,
paddingVertical: 5 paddingVertical: 5
} }

View file

@ -89,6 +89,8 @@ export default class DiaryBrief extends Component {
<Photo uri={diary.photoThumbUrl} onPress={this.props.onPhotoPress}></Photo> <Photo uri={diary.photoThumbUrl} onPress={this.props.onPhotoPress}></Photo>
<View style={localStyle.actionBar}> <View style={localStyle.actionBar}>
<View style={{flex: 1}} />
<View style={localStyle.icons}> <View style={localStyle.icons}>
<DiaryIconComment count={diary.comment_count}></DiaryIconComment> <DiaryIconComment count={diary.comment_count}></DiaryIconComment>
<DiaryIconOkB diaryId={diary.id} <DiaryIconOkB diaryId={diary.id}
@ -98,7 +100,7 @@ export default class DiaryBrief extends Component {
refreshBack={this.refreshDiary.bind(this)} refreshBack={this.refreshDiary.bind(this)}
></DiaryIconOkB> ></DiaryIconOkB>
</View> </View>
<View style={{flex: 1}} />
{ {
isMine && !expired isMine && !expired
? <TouchableOpacity onPress={this.onDiaryAction.bind(this)}> ? <TouchableOpacity onPress={this.onDiaryAction.bind(this)}>
@ -134,7 +136,8 @@ const localStyle = StyleSheet.create({
title: { title: {
flexDirection: "row", flexDirection: "row",
alignItems: "flex-end", alignItems: "flex-end",
paddingBottom: 5 paddingBottom: 5,
paddingRight: 9
}, },
titleName: { titleName: {
fontWeight: 'bold', fontWeight: 'bold',
@ -164,7 +167,7 @@ const localStyle = StyleSheet.create({
flexDirection: 'row' flexDirection: 'row'
}, },
moreIcon: { moreIcon: {
paddingVertical: 5, marginLeft: 7,
paddingHorizontal: 5 marginRight: 13
} }
}); });

View file

@ -157,7 +157,7 @@ const localStyle = StyleSheet.create({
title: { title: {
flexDirection: "row", flexDirection: "row",
alignItems: "flex-end", alignItems: "flex-end",
paddingRight: 10, paddingRight: 9,
paddingBottom: 5 paddingBottom: 5
}, },
titleName: { titleName: {

View file

@ -29,9 +29,11 @@ export default class DiaryIconComment extends Component {
const localStyle = StyleSheet.create({ const localStyle = StyleSheet.create({
wrap: { wrap: {
flexDirection: 'row', flexDirection: 'row',
marginRight: 6 marginRight: 6,
marginTop: -1
}, },
icon: { icon: {
color: Color.inactiveText,
marginLeft: 2, marginLeft: 2,
marginRight: 4 marginRight: 4
}, },

View file

@ -101,8 +101,8 @@ const localStyle = StyleSheet.create({
icon: { icon: {
width: 18, width: 18,
height: 18, height: 18,
marginLeft: 2, marginLeft: 4,
marginRight: 4 marginRight: 1
}, },
text: { text: {
fontSize: 15 fontSize: 15

View file

@ -53,6 +53,15 @@ export default class DiaryList extends Component {
} }
scrollToTop() { scrollToTop() {
if(!this.scrollY) {
this.scrollY = 0;
}
if(this.scrollY <= 10) {
this.refresh();
return;
}
this.list.scrollToOffset({ this.list.scrollToOffset({
offset: 0 offset: 0
}); });
@ -263,6 +272,10 @@ export default class DiaryList extends Component {
onEndReachedThreshold={2} onEndReachedThreshold={2}
onEndReached={this.state.hasMore ? this.loadMore.bind(this) : null} onEndReached={this.state.hasMore ? this.loadMore.bind(this) : null}
onScroll={(event) => {
this.scrollY = event.nativeEvent.contentOffset.y;
}}
> >
</FlatList> </FlatList>

View file

@ -86,10 +86,10 @@ export default class NotebookDiaryList extends Component {
} }
refreshOne(index, diary) { refreshOne(index, diary) {
console.log('index, diary:', index, diary);
if(diary) { if(diary) {
let list = this.state.rawlist; let list = this.state.rawlist;
diary.user = list[index].user; diary.user = list[index].user;
list[index] = diary; list[index] = diary;
this.setState({ this.setState({
@ -188,8 +188,18 @@ export default class NotebookDiaryList extends Component {
diary: diary, diary: diary,
showField: ['createdTime'], showField: ['createdTime'],
expired: this.notebook.isExpired, expired: this.notebook.isExpired
refreshBack: this.refreshOne.bind(this, index) }
}
});
}
_onPhotoPress(photoUrl) {
Navigation.push(this.props.componentId, {
component: {
name: 'Photo',
passProps: {
url: photoUrl
} }
} }
}); });
@ -215,13 +225,14 @@ export default class NotebookDiaryList extends Component {
renderItem={(rowData) => { renderItem={(rowData) => {
return ( return (
<DiaryBrief <DiaryBrief {...this.props}
diary={rowData.item} diary={rowData.item}
showField={['createdTime']} showField={['createdTime']}
expired={expired} expired={expired}
isMine={isMine} isMine={isMine}
onDiaryPress={this._onDiaryPress.bind(this, rowData.index)} onDiaryPress={this._onDiaryPress.bind(this, rowData.index)}
onPhotoPress={() => this._onPhotoPress(rowData.item.photoUrl)}
refreshBack={this.refreshOne.bind(this, rowData.index)} refreshBack={this.refreshOne.bind(this, rowData.index)}
> >

View file

@ -12,6 +12,12 @@ export default class UserIcon extends Component {
}; };
} }
static getDerivedStateFromProps(nextProps, prevState) {
return {
iconUrl: nextProps.iconUrl
};
}
_defaultOnPress() { _defaultOnPress() {
// empty // empty
} }

View file

@ -30,7 +30,7 @@ function getTodayStr() {
let month = now.getMonth() + 1; let month = now.getMonth() + 1;
let date = now.getDate(); let date = now.getDate();
return year + '-' + (month > 9 ? month : '0' + month) + '-' + date; return year + '-' + (month > 9 ? month : '0' + month) + '-' + (date > 9 ? date : '0' + date);
} }
export default class DiaryDetailPage extends Component { export default class DiaryDetailPage extends Component {

View file

@ -52,10 +52,20 @@ export default class FollowPage extends Component {
}); });
} }
componentDidMount() {
this.bottomTabEventListener = Navigation.events().registerBottomTabSelectedListener(
({ selectedTabIndex, unselectedTabIndex }) => {
if(selectedTabIndex == unselectedTabIndex && selectedTabIndex == 1) {
this.diaryList.scrollToTop();
}
}
);
}
render() { render() {
return ( return (
<View style={localStyle.wrap}> <View style={localStyle.wrap}>
<DiaryList ref={(r) => this.list = r} <DiaryList ref={(r) => this.diaryList = r}
dataSource={this.dataSource} dataSource={this.dataSource}
{...this.props} {...this.props}

View file

@ -119,7 +119,10 @@ export default class HomePage extends Component {
} }
}, },
bottomTabs: { bottomTabs: {
visible: true visible: true,
drawBehind: false,
animate: false
} }
}); });

View file

@ -147,8 +147,10 @@ export default class NotificationPage extends Component {
} }
refresh() { refresh() {
if(this.list) {
this.list.refresh(false); this.list.refresh(false);
} }
}
_onDeletePress(msg) { _onDeletePress(msg) {
this._setRead(msg).done(); this._setRead(msg).done();

View file

@ -114,6 +114,14 @@ export default class SettingPage extends Component {
Alert.alert('提示','确认退出登录?',[ Alert.alert('提示','确认退出登录?',[
{text: '退出', style: 'destructive', onPress: () => { {text: '退出', style: 'destructive', onPress: () => {
Api.logout(); Api.logout();
/*
* clear ActionSheet instance
*/
if(global.__action_sheet) {
global.__action_sheet = null;
}
Navigation.setRoot({ Navigation.setRoot({
root: { root: {
stack: { stack: {

View file

@ -30,7 +30,7 @@ export default class UserPage extends Component {
this.dataSource = new UserDiaryData(this.userId); this.dataSource = new UserDiaryData(this.userId);
this.state = { this.state = {
index: 1, index: this.user ? 0 : 1,
routes: [ routes: [
{ key: 'userIntro', title: '简介' }, { key: 'userIntro', title: '简介' },
{ key: 'diary', title: '日记' }, { key: 'diary', title: '日记' },

View file

@ -100,6 +100,7 @@ export default class WritePage extends Component {
componentDidMount() { componentDidMount() {
this.loadNotebook(); this.loadNotebook();
this.contentInput.focus();
this.notebookListener = DeviceEventEmitter.addListener(Event.updateNotebooks, (param) => { this.notebookListener = DeviceEventEmitter.addListener(Event.updateNotebooks, (param) => {
this.loadNotebook(true); this.loadNotebook(true);
@ -111,6 +112,7 @@ export default class WritePage extends Component {
} }
openModal() { openModal() {
this.contentInput.blur();
this.setState({modalVisible: true}); this.setState({modalVisible: true});
if(this.state.notebooks.length == 0) { if(this.state.notebooks.length == 0) {
@ -120,15 +122,14 @@ export default class WritePage extends Component {
} }
} }
closeModal(showKeyboard = true) { closeModal(showKeyboard = true, callback) {
this.contentInput.blur();
Animated.parallel([ Animated.parallel([
Animated.timing( Animated.timing(
this.state.fadeAnimOpacity, this.state.fadeAnimOpacity,
{ {
toValue: 0, toValue: 0,
duration: 350, duration: 350,
easing: Easing.out(Easing.cubic) easing: Easing.out(Easing.linear)
} }
), ),
Animated.timing( Animated.timing(
@ -136,27 +137,36 @@ export default class WritePage extends Component {
{ {
toValue: 0, toValue: 0,
duration: 350, duration: 350,
easing: Easing.out(Easing.cubic) easing: Easing.out(Easing.linear)
} }
) )
]).start(({finished}) => { ]).start(({finished}) => {
this.setState({modalVisible: false});
if(!finished) { if(!finished) {
return; return;
} }
this.setState({modalVisible: false}, () => {
setTimeout(() => {
if(showKeyboard) { if(showKeyboard) {
setTimeout(() => this.contentInput.focus(), 100); this.contentInput.focus()
} else {
if(typeof callback == 'function') {
callback();
} }
}
}, 100);
});
}); });
} }
_onCreateNotebook() { _onCreateNotebook() {
this.closeModal(false); this.closeModal(false, () => {
Navigation.push(this.props.componentId, { Navigation.push(this.props.componentId, {
component: { component: {
name: 'NotebookEdit' name: 'NotebookEdit'
} }
}); });
});
} }
_onNotebookSelected(notebook) { _onNotebookSelected(notebook) {
@ -241,13 +251,25 @@ export default class WritePage extends Component {
} }
saveDiary() { saveDiary() {
if(!this.state.content) {
return;
}
let photoUri = this.state.photoUri; let photoUri = this.state.photoUri;
let topic = this.props.topic ? 1 : 0; let topic = this.props.topic ? 1 : 0;
let waitingToast = Msg.showMsg('正在保存中', {
duration: 10000,
position: -75,
shadow: false,
hideOnPress: false
});
(this.diary (this.diary
? Api.updateDiary(this.diary.id, this.state.targetbookId, this.state.content) ? Api.updateDiary(this.diary.id, this.state.targetbookId, this.state.content)
: Api.addDiary(this.state.targetbookId, this.state.content, photoUri, topic) : Api.addDiary(this.state.targetbookId, this.state.content, photoUri, topic)
).then(result => { ).then(result => {
Msg.hideMsg(waitingToast);
Msg.showMsg('日记保存完成'); Msg.showMsg('日记保存完成');
DeviceEventEmitter.emit(Event.updateDiarys); DeviceEventEmitter.emit(Event.updateDiarys);
@ -271,6 +293,7 @@ export default class WritePage extends Component {
} }
}) })
.catch(e => { .catch(e => {
Msg.hideMsg(waitingToast);
Msg.showMsg('保存失败'); Msg.showMsg('保存失败');
}) })
.done(); .done();

View file

@ -14,9 +14,14 @@ function showMsg(msg, option) {
} }
} }
Toast.show(msg, option); return Toast.show(msg, option);
}
function hideMsg(toast) {
Toast.hide(toast);
} }
export default { export default {
showMsg showMsg,
hideMsg
} }