Skip to content

Commit

Permalink
Merge pull request #15 from hecom-rn/hanhu
Browse files Browse the repository at this point in the history
群聊名称完善编辑
  • Loading branch information
summer88123 authored Jan 4, 2021
2 parents afffa24 + b0a444d commit 62c1bdf
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 27 deletions.
25 changes: 20 additions & 5 deletions plugin/setting/GroupName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React from 'react';
import { View } from 'react-native';
import Toast from 'react-native-root-toast';
import i18n from 'i18n-js';
import { Typings, Delegate } from '../../standard';
import { Typings, Delegate, PageKeys } from '../../standard';
import Prompt from './Prompt';

export const name = 'IMSettingGroupName';

export function getUi(props: Typings.Action.Setting.Params): Typings.Action.Setting.Result {
const {key, imId, chatType, onDataChange} = props;
const {key, imId, chatType, onDataChange,navigation} = props;
const isGroup = chatType === Typings.Conversation.ChatType.Group;
if (!isGroup) {
return null;
Expand All @@ -25,6 +25,7 @@ export function getUi(props: Typings.Action.Setting.Params): Typings.Action.Sett
isOwner={isOwner}
groupName={groupName}
imId={imId}
navigation={navigation}
onDataChange={onDataChange}
/>
);
Expand All @@ -48,7 +49,7 @@ export class GroupNameCell extends React.PureComponent<Props, State> {

render() {
const {groupName, isOwner} = this.props;
const showNameLineFunc = !isOwner ? undefined : this._changePromptStatus.bind(this, true);
const showNameLineFunc = !isOwner ? undefined : this._clickNameEdit.bind(this);
return (
<View>
<Delegate.component.SettingItem
Expand All @@ -57,13 +58,13 @@ export class GroupNameCell extends React.PureComponent<Props, State> {
data={groupName}
onPressLine={showNameLineFunc}
/>
<Prompt
{/* <Prompt
visible={this.state.showPrompt}
title={i18n.t('IMSettingGroupNameChangeTips')}
onCancel={this._changePromptStatus.bind(this, false)}
onSubmit={this._clickName.bind(this)}
textInputProps={{secureTextEntry: false}}
/>
/> */}
</View>
);
}
Expand All @@ -89,4 +90,18 @@ export class GroupNameCell extends React.PureComponent<Props, State> {
}));
});
}

protected _clickNameEdit() {
const {imId, onDataChange, groupName, navigation, onSendMessage} = this.props;
const curGroupName = (groupName != null) ? groupName : ''
const groupAvatar = { imId: imId, chatType:Typings.Conversation.ChatType.Group };

navigation.navigate( PageKeys.GroupNameEdit, {
groupId: imId,
groupName: curGroupName,
groupAvatar: groupAvatar,
onDataChange: onDataChange,
onSendMessage: onSendMessage,
})
}
}
1 change: 1 addition & 0 deletions standard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function setup_common_page() {
Delegate.page[PageKeys.GroupAnnouncementEdit] = Pages.GroupAnnouncementEditPage;
Delegate.page[PageKeys.Search] = Pages.SearchPage;
Delegate.page[PageKeys.SearchMore] = Components.SearchList;
Delegate.page[PageKeys.GroupNameEdit] = Pages.GroupNameEdit;
}

function setup_common_render() {
Expand Down
3 changes: 2 additions & 1 deletion standard/model/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ export async function onMessageReceived(
originMessage: Message.Origin
): Promise<ProcessedMessage> {
//语音消息插入未读标志
//语音消息插入未点击标志
const {ext} = originMessage;
if (ext &&
ext.extend_message_body &&
ext.extend_message_body.messageType &&
ext.extend_message_body.messageType.messageType == 5) {
ext.extend_message_body.messageType == 5) {
originMessage.ext.shouldRead = true;
delegate.im.conversation.updateMessageExt(originMessage.messageId, originMessage.ext);
}
Expand Down
36 changes: 23 additions & 13 deletions standard/page/ChatDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {Clipboard, Keyboard, SafeAreaView, StyleSheet, TouchableWithoutFeedback, View, Alert} from 'react-native';
import {Clipboard, Keyboard, SafeAreaView, StyleSheet, TouchableWithoutFeedback,Image, View, Alert,Text,TouchableOpacity} from 'react-native';
import {HeaderButton} from 'react-navigation-header-buttons';
import Toast from 'react-native-root-toast';
import Listener from '@hecom/listener';
Expand Down Expand Up @@ -169,18 +169,23 @@ export default class extends React.PureComponent<ChatDetailProps> {
_renderRightElement() {
const {imId, chatType} = this.props;
const onSendMsg = this._onSendMessage.bind(this, imId, chatType)
return (
<HeaderButton
title={i18n.t('IMPageChatDetailSetting')}
onPress={() => {
this.props.navigation.navigate( PageKeys.ChatSetting,{
imId: imId,
chatType: chatType,
onSendMessage: onSendMsg,
});
}}
/>
);
const moreImage = require('./image/showMore.png');
return (<TouchableOpacity
onPress={() => {
this.props.navigation.navigate( PageKeys.ChatSetting,{
imId: imId,
chatType: chatType,
onSendMessage: onSendMsg,
});
}}
activeOpacity={0.8}
>
<Image
source={moreImage}
style={styles.rightImage}
/>
</TouchableOpacity>
)
}

_setKeyboardStatus(status) {
Expand Down Expand Up @@ -418,4 +423,9 @@ const styles = StyleSheet.create({
container: {
flex: 1,
},
rightImage: {
width: 24,
height: 24,
right: 10,
},
});
7 changes: 0 additions & 7 deletions standard/page/ChatSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ export default class extends React.PureComponent {
return {title};
};

// static propTypes = {
// ...Types.BasicConversation,
// ...Types.Navigation,
// sections: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.string)),
// buttons: PropTypes.arrayOf(PropTypes.string),
// };

static defaultProps = {
sections: [],
buttons: [],
Expand Down
223 changes: 223 additions & 0 deletions standard/page/GroupNameEdit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
import React from 'react';
import {Keyboard, Platform, Image ,StyleSheet, Text, TextInput, Dimensions, View} from 'react-native';
import PropTypes from 'prop-types';
import NaviBar, {getSafeAreaInset} from '@hecom/react-native-pure-navigation-bar';
import {Delegate} from "react-native-im/standard/index";
import Toast from "react-native-root-toast";
import i18n from 'i18n-js';
import Navigation from "@hecom/navigation/src/index";
import delegate from "react-native-im/standard/delegate";

const { width, height } = Dimensions.get('window');

export default class extends React.PureComponent {
private keyboardDidShowListener: any;
private keyboardDidHideListener: any;
private isDisable = true

static propTypes = {
groupId: PropTypes.string.isRequired,
groupName: PropTypes.string.isRequired,
onDataChange: PropTypes.func.isRequired,
};

state = {
keyBoardHeight: 0,
}

componentWillMount() {
if (Platform.OS === 'ios') {
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow.bind(this));
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide.bind(this));
}
}
componentWillUnmount() {
if (Platform.OS === 'ios') {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}
}
protected _keyboardDidShow(e) {
if (Platform.OS === 'ios') {
this.setState({
keyBoardHeight: e.endCoordinates.height
});
}
}
protected _keyboardDidHide() {
if (Platform.OS === 'ios') {
this.setState({
keyBoardHeight: 0
});
}
}

render() {
const { groupName } = this.props;
// const rights = {};
// rights.rightElement = '保存';
// if (this.isDisable) {
// rights.rightElementDisable = true;
// } else {
// rights.onRight = this._onRight;
// }
const safeArea = getSafeAreaInset();
const marginStyle = {marginBottom: Math.max(this.state.keyBoardHeight, 10) + safeArea.bottom};
return (
<View style={styles.container}>
<NaviBar title={''} autoCloseKeyboard={true} hasSeperatorLine={false}/>
<Text style={styles.titleText}>{'修改群聊名称'}</Text>
<View style={styles.topLineView} />
<View style={styles.backView}>
{this._renderIcon()}
<TextInput
style={styles.input}
defaultValue={groupName}
maxLength={2000}
multiline={false}
clearButtonMode={'while-editing'}
placeholder='请输入群名'
onChangeText={(text) => {
this.isDisable = false
this.setState({text})
}}
autoFocus={true}
/>
</View>
<View style={styles.bottomLineView} />
<View style={[styles.buttonView,marginStyle]}>
<Text style={styles.button} onPress={() => {
if (!this.isDisable) {
this._onRight()
} else {
Navigation.pop();
}
}}>
{'完成'}
</Text>
</View>
</View>
);
}

protected _onRight = () => {
// const {groupId, onDataChange} = this.props;
let newName = this.state.text;
if (!newName) {
newName = ''
}
this.props.apiRefresh(true);

if (!newName || newName.length === 0) {
Toast.show(i18n.t('IMSettingGroupNameNotEmpty'));
return;
}
const {groupId, onDataChange} = this.props;
Delegate.model.Group.changeName(groupId, newName)
.then(() => {
this.props.apiRefresh(false);
onDataChange();
Toast.show('保存成功');
Navigation.pop();
})
.catch(() => {
this.props.apiRefresh(false);
Toast.show(i18n.t('IMToastError', {
action: i18n.t('IMSettingGroupNameChange'),
}));
});
};

_renderIcon = () => {
const {groupAvatar} = this.props;
const isAvatar = Object.prototype.isPrototypeOf(groupAvatar) && groupAvatar.imId;
if (isAvatar) {
return (
<Delegate.component.AvatarImage
{...groupAvatar}
style={styles.avatar}
/>
);
} else {
const src = typeof groupAvatar === 'string' ?
{uri: delegate.func.fitUrlForAvatarSize(groupAvatar, 48)} :
groupAvatar;
return <Image style={styles.icon} source={src} />;
}
};
}

const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
flex: 1,
position: 'absolute',
height: height,
width: width,
},
backView: {
top: 108,
left: 20,
width: width - 40,
flexDirection: 'row',
backgroundColor: 'white',
},
topLineView: {
height: 1,
width: width - 40,
left: 20,
top: 100,
backgroundColor: 'rgba(25,31,37,0.08)',
},
bottomLineView: {
height: 1,
width: width - 40,
left: 20,
top: 115,
backgroundColor: 'rgba(25,31,37,0.08)',
},
input: {
fontSize: 14,
justifyContent: 'center',
marginTop: 10,
marginHorizontal: 12,
...Platform.select({
android: { textAlignVertical: 'top' },
}),
flex: 1,
},
avatar: {

},
icon: {
height: 48,
width: 48,
borderRadius: 24,
overflow: 'hidden',
},
titleText: {
height: 40,
fontSize: 20,
fontWeight: 'bold',
textAlign:'center',
top: 60,
left: 0,
width: width,
},
button: {
color: 'rgba(24, 144, 255, 1)',
fontSize: 15,
textAlign: 'center',
width: 120,
},
buttonView: {
backgroundColor: 'rgba(25,31,37,0.08)',
height: 40,
width: 150,
borderRadius: 5,
alignItems: 'center',
justifyContent: 'center',
top: 150,
left: (width - 150)/2,
},
});
Binary file added standard/page/image/showMore@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions standard/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import GroupListPage from './GroupList';
import GroupMembersPage from './GroupMembers';
import GroupAnnouncementEditPage from './GroupAnnouncementEdit';
import SearchPage from './Search';
import GroupNameEdit from './GroupNameEdit';

export {
ChatDetailPage,
Expand All @@ -22,4 +23,5 @@ export {
GroupMembersPage,
SearchPage,
GroupAnnouncementEditPage,
GroupNameEdit,
};
Loading

0 comments on commit 62c1bdf

Please sign in to comment.