diff --git a/index.js b/index.js index 01363f0..ed157a5 100644 --- a/index.js +++ b/index.js @@ -3,13 +3,13 @@ */ import {Navigation} from 'react-native-navigation'; -import {Icon, loadIcon} from './src/style/icon' +import {Icon, loadIcon} from './src/style/icon'; import App from './App'; -import Token from './src/util/token' -import PageList from './src/page/_list' -import BottomNav from './src/nav/bottomNav' +import Token from './src/util/token'; +import PageList from './src/page/_list'; +import BottomNav from './src/nav/bottomNav'; async function init() { diff --git a/src/component/comment/comment.js b/src/component/comment/comment.js new file mode 100644 index 0000000..0bd56c6 --- /dev/null +++ b/src/component/comment/comment.js @@ -0,0 +1,95 @@ +import React, {Component} from 'react'; +import {StyleSheet, Text, View} from 'react-native'; +import moment from 'moment'; + +import Color from '../../style/color'; +import UserIcon from '../userIcon'; + +import CommentActionIcon from './commentActionIcon'; + + +export default class Comment extends Component { + + render() { + let comment = this.props.comment; + let user = comment.user; + let editable = this.props.editable || true; + + return ( + + + + + + + {user.name} + {moment(comment.created).format('H:mm')} + + { + comment.recipient == null + ? {comment.content} + : ( + + @{comment.recipient.name} + {comment.content} + + ) + } + + + + { + editable + ? + : null + } + + + + + ); + } +} + +const localStyle = StyleSheet.create({ + box: { + paddingVertical: 15, + paddingHorizontal: 15, + flexDirection: 'row' + }, + body: { + flexDirection: 'column', + flexGrow: 1, + flexShrink: 1, + paddingTop: 2 + }, + title: { + flexDirection: 'row', + paddingBottom: 5, + alignItems: 'flex-end' + }, + titleName: { + flexGrow: 1, + fontWeight: 'bold', + color: Color.text, + fontSize: 14, + marginRight: 5 + }, + titleText: { + fontSize: 12, + color: Color.inactiveText + }, + content: { + flexGrow: 1, + lineHeight: 26, + color: Color.text, + fontSize: 15, + marginBottom: 10 + }, + line: { + height: StyleSheet.hairlineWidth, + backgroundColor: Color.line, + marginHorizontal: 16, + marginLeft: 56 + } +}); \ No newline at end of file diff --git a/src/component/comment/commentActionIcon.js b/src/component/comment/commentActionIcon.js new file mode 100644 index 0000000..1682a74 --- /dev/null +++ b/src/component/comment/commentActionIcon.js @@ -0,0 +1,37 @@ +import React, {Component} from 'react'; +import {StyleSheet, Text, View, TouchableOpacity, Alert} from 'react-native'; +import Icon from 'react-native-vector-icons/Ionicons'; +import ActionSheet from 'react-native-actionsheet-api'; + +import Color from '../../style/color' + + +export default class CommentActionIcon extends Component { + + _defaultOnPress() { + + } + + render() { + return ( + + + + + ); + } +} + +const localStyle = StyleSheet.create({ + moreIcon: { + position: 'absolute', + bottom: 0, + right: 10, + paddingHorizontal: 12, + paddingVertical: 5 + } +}); diff --git a/src/component/comment/commentList.js b/src/component/comment/commentList.js new file mode 100644 index 0000000..d2fa810 --- /dev/null +++ b/src/component/comment/commentList.js @@ -0,0 +1,84 @@ +import React, {Component} from 'react'; +import { + InteractionManager, + ActivityIndicator, + StyleSheet, + FlatList, + Text, View +} from 'react-native'; +import {Divider} from "react-native-elements"; + +import Touchable from '../touchable'; +import Color from '../../style/color'; +import Api from '../../util/api'; + +import Comment from './comment'; + + +export default class CommentList extends Component { + + constructor(props) { + super(props); + + this.diaryId = props.diaryId; + this.state = { + comments: [] + }; + } + + componentDidMount() { + InteractionManager.runAfterInteractions(() => { + this.loadMore(); + }); + } + + async loadMore() { + console.log('commentList:', this.diaryId); + + let comments = await Api.getDiaryComments(this.diaryId); + console.log('comments:', comments); + + if(comments && comments.length > 0) { + if (comments.length > 1) { + comments = comments.reverse(); + } + + this.setState({ + comments + }); + } + } + + render() { + return ( + + { + return item.id.toString() + }} + + renderItem={({item}) => { + return ( + {}}> + + + ) + }} + > + + + ); + } +} + +const localStyle = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: Color.navBackground, + justifyContent: 'space-between', + paddingBottom: Api.IS_IPHONEX ? 30 : 0 + } +}); \ No newline at end of file diff --git a/src/component/diary/diaryBrief.js b/src/component/diary/diaryBrief.js index ff4ccaa..510229e 100644 --- a/src/component/diary/diaryBrief.js +++ b/src/component/diary/diaryBrief.js @@ -1,13 +1,13 @@ import React, {Component} from 'react'; import {StyleSheet, Text, View} from 'react-native'; -import moment from 'moment' +import moment from 'moment'; -import Color from '../../style/color' -import UserIcon from './userIcon' -import Photo from '../photo' +import Color from '../../style/color'; +import UserIcon from '../userIcon'; +import Photo from '../photo'; -import CommentIcon from '../comment/commentIcon' -import DiaryActionIcon from './diaryActionIcon' +import CommentIcon from '../comment/commentIcon'; +import DiaryActionIcon from './diaryActionIcon'; export default class DiaryBrief extends Component { diff --git a/src/component/diary/diaryFull.js b/src/component/diary/diaryFull.js index 9320b1f..966c0d3 100644 --- a/src/component/diary/diaryFull.js +++ b/src/component/diary/diaryFull.js @@ -1,54 +1,68 @@ import React, {Component} from 'react'; import {Platform, StyleSheet, Text, View} from 'react-native'; -import moment from 'moment' +import moment from 'moment'; -import Color from '../../style/color' -import UserIcon from './userIcon' +import Color from '../../style/color'; +import UserIcon from '../userIcon'; +import Photo from '../photo'; + +import CommentList from '../comment/commentList'; export default class DiaryFull extends Component { render() { - let diary = this.props.diary; - let user = diary.user; + let diary = this.props.diary; + let user = diary.user; + let editable = this.props.editable; - return ( - - - - - - {user.name} - - - 《{diary.notebook_subject}》 - - - {moment(diary.created).format('H:mm')} - + return ( + + + + + + + {user.name} + + + 《{diary.notebook_subject}》 + + + {moment(diary.created).format('H:mm')} + + + + + {diary.content.trim()} + + + + - - {diary.content} - + + - - ); + ); } } + const localStyle = StyleSheet.create({ box: { flexDirection: "row", overflow: "hidden", paddingHorizontal: 15, - paddingTop: 15 + paddingTop: 15, + marginBottom: 30 }, body: { flexDirection: "column", flexGrow: 1, flexShrink: 1, - paddingTop: 2 + paddingTop: 2, + paddingBottom: 5 }, title: { flexDirection: "row", @@ -69,7 +83,6 @@ const localStyle = StyleSheet.create({ lineHeight: 24, color: Color.text, fontSize: 15, - textAlignVertical: 'bottom', - paddingBottom: 15 + textAlignVertical: 'bottom' } }); diff --git a/src/component/diary/diaryList.js b/src/component/diary/diaryList.js index 58b4ccb..bc009e1 100644 --- a/src/component/diary/diaryList.js +++ b/src/component/diary/diaryList.js @@ -8,12 +8,12 @@ import { } from 'react-native'; import {Divider} from "react-native-elements"; -import Color from '../../style/color' -import Msg from '../../util/msg' -import Api from '../../util/api' +import Color from '../../style/color'; +import Msg from '../../util/msg'; +import Api from '../../util/api'; -import Touchable from '../touchable' -import DiaryBrief from './diaryBrief' +import Touchable from '../touchable'; +import DiaryBrief from './diaryBrief'; export default class DiaryList extends Component { @@ -34,7 +34,6 @@ export default class DiaryList extends Component { } componentDidMount() { - console.log('diaryList mounted.'); InteractionManager.runAfterInteractions(() => { this.refresh(); }); @@ -101,13 +100,13 @@ export default class DiaryList extends Component { } _onDiaryPress(diary) { - /* + this.props.navigator.push({ screen: 'DiaryDetail', title: '日记详情', passProps: { diary: diary } }); - */ + } render() { diff --git a/src/component/diary/userIcon.js b/src/component/userIcon.js similarity index 100% rename from src/component/diary/userIcon.js rename to src/component/userIcon.js diff --git a/src/page/DiaryDetailPage.js b/src/page/DiaryDetailPage.js new file mode 100644 index 0000000..5d21149 --- /dev/null +++ b/src/page/DiaryDetailPage.js @@ -0,0 +1,21 @@ +import React, {Component} from 'react'; +import {Platform, StyleSheet, Text, View, ScrollView} from 'react-native'; + +import Color from '../style/color'; +import DiaryFull from '../component/diary/diaryFull'; + + +export default class DiaryDetailPage extends Component { + + render() { + return ( + + + + ); + } +} + +const localStyle = StyleSheet.create({ + +}); diff --git a/src/page/HomePage.js b/src/page/HomePage.js index b7f8ffe..b49215e 100644 --- a/src/page/HomePage.js +++ b/src/page/HomePage.js @@ -1,7 +1,7 @@ import React, {Component} from 'react'; import {StyleSheet, Text, View} from 'react-native'; -import Api from '../util/api' +import Api from '../util/api'; import DiaryList from '../component/diary/diaryList' import HomeListData from '../dataLoader/homeListData'; diff --git a/src/page/_list.js b/src/page/_list.js index 1bfe05c..30b948f 100644 --- a/src/page/_list.js +++ b/src/page/_list.js @@ -1,4 +1,5 @@ export default { +DiaryDetail: require("./DiaryDetailPage.js").default, Follow: require("./FollowPage.js").default, Home: require("./HomePage.js").default, Notification: require("./NotificationPage.js").default, diff --git a/src/util/api.js b/src/util/api.js index 093e633..978c6cc 100644 --- a/src/util/api.js +++ b/src/util/api.js @@ -64,7 +64,9 @@ async function getFollowDiaries(page = 1, page_size = 20, first_id = '') { }); } - +async function getDiaryComments(diaryId) { + return call('GET', '/diaries/' + diaryId + '/comments') +} async function call(method, api, body, _timeout = 10000) { @@ -154,5 +156,6 @@ export default { login, getTodayDiaries, - getFollowDiaries + getFollowDiaries, + getDiaryComments } \ No newline at end of file