diff --git a/ReactNative/sample/App.js b/ReactNative/sample/App.js index 59a78e1f..eabc6a18 100644 --- a/ReactNative/sample/App.js +++ b/ReactNative/sample/App.js @@ -147,7 +147,7 @@ export default class TestRNIMUI extends Component { isAllowPullToRefresh: true, navigationBar: {}, } - + this.updateLayout = this.updateLayout.bind(this); this.onMsgClick = this.onMsgClick.bind(this); @@ -170,13 +170,13 @@ export default class TestRNIMUI extends Component { messageListDidLoadEvent() { this.getHistoryMessage() } - + getHistoryMessage() { var messages = [] for (var index in imageUrlArray) { var message = constructNormalMessage() message.fromUser.avatarUrl = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534926548887&di=f107f4f8bd50fada6c5770ef27535277&imgtype=0&src=http%3A%2F%2Fpic.58pic.com%2F58pic%2F11%2F67%2F23%2F69i58PICP37.jpg",//1 - message.msgType = 'image' + message.msgType = 'image' message.mediaPath = imageUrlArray[index] message.contentSize = { 'height': 100, 'width': 200 } message.extras = { "extras": "fdfsf" } @@ -276,7 +276,7 @@ export default class TestRNIMUI extends Component { } onMsgLongClick = (message) => { - Alert.alert('message bubble on long press', 'message bubble on long press') + Alert.alert('获取长按时的数据', JSON.stringify(message)) } onStatusViewClick = (message) => { @@ -454,7 +454,7 @@ export default class TestRNIMUI extends Component { inputViewLayout: { flex: 1, width: window.width, height: window.height }, navigationBar: { height: 0 } }) - } + } } render() { @@ -509,6 +509,7 @@ export default class TestRNIMUI extends Component { isAllowPullToRefresh={true} onAvatarClick={this.onAvatarClick} onMsgClick={this.onMsgClick} + onMsgLongClick={this.onMsgLongClick} onStatusViewClick={this.onStatusViewClick} onTouchMsgList={this.onTouchMsgList} onTapMessageCell={this.onTapMessageCell} @@ -557,7 +558,7 @@ export default class TestRNIMUI extends Component { customLayoutItems={{ left: [], right: ['send'], - bottom: ['voice','gallery','emoji','camera'] + bottom: ['voice', 'gallery', 'emoji', 'camera'] }} /> diff --git a/ReactNative/sample/README.md b/ReactNative/sample/README.md new file mode 100644 index 00000000..6f97b437 --- /dev/null +++ b/ReactNative/sample/README.md @@ -0,0 +1,70 @@ +##### 新增react-native安卓端,消息长按时,获取当前消息的偏移距离(x,y)和当前消息框的width和height。 +###### 修改方式:主要增加Android端原生方法view.getLocationOnScreen()用于获取当前view的位置和width,height; +###### Android studio打开/aurora-imui/ReactNative/sample/android项目,在依赖库‘aurora-imui-react-native’中修改相关方法: +* 在ReactMsgListManager.java中setMsgLongClickListener方法里面添加: + int[] location = new int[2]; + view.getLocationOnScreen(location); + int x = location[0];//获取当前位置的横坐标 + int y = location[1];//获取当前位置的纵坐标 + message.setView_x(px2dp(mContext, x)); + message.setView_y(px2dp(mContext, y)); + message.setMsg_width(px2dp(mContext,view.getWidth()));//当前消息的的宽和高 + message.setMsg_height(px2dp(mContext,view.getHeight())); + + 此处还有一个px转dp的方法: + public static int px2dp(Context context, float pxValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (pxValue / scale + 0.5f); + } + + +* 在RCTMessage.java这个实体类中,添加对应的字段: + public static final String VIEW_X = "viewx"; + public static final String VIEW_Y = "viewy"; + public static final String MSG_WIDTH="msg_width"; + public static final String MSG_HEIGHT="msg_height"; + private int view_x; + private int view_y; + private int msg_width; + private int msg_height; + + public int getMsg_width() { + return msg_width; + } + + public void setMsg_width(int msg_width) { + this.msg_width = msg_width; + } + + public int getMsg_height() { + return msg_height; + } + + public void setMsg_height(int msg_height) { + this.msg_height = msg_height; + } + + public int getView_x() { + return view_x; + } + + public void setView_x(int view_x) { + this.view_x = view_x; + } + + public int getView_y() { + return view_y; + } + + public void setView_y(int view_y) { + this.view_y = view_y; + } + + 最后在toJSON()方法中添加: + json.addProperty(VIEW_X, view_x); + json.addProperty(VIEW_Y, view_y); + json.addProperty(MSG_WIDTH,msg_width); + json.addProperty(MSG_HEIGHT,msg_height); + + + diff --git a/ReactNative/sample/yarn.lock b/ReactNative/sample/yarn.lock index 4199ac3f..f890ed53 100644 --- a/ReactNative/sample/yarn.lock +++ b/ReactNative/sample/yarn.lock @@ -239,6 +239,10 @@ atob@^2.1.1: version "2.1.1" resolved "https://registry.npmjs.org/atob/-/atob-2.1.1.tgz#ae2d5a729477f289d60dd7f96a6314a22dd6c22a" +aurora-imui-react-native@^0.13.1: + version "0.13.1" + resolved "http://registry.npm.taobao.org/aurora-imui-react-native/download/aurora-imui-react-native-0.13.1.tgz#db65ce76ce9b314110651e5acc58bcb88823977a" + aws-sign2@~0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.6.0.tgz#14342dd38dbcc94d0e5b87d763cd63612c0e794f"