77 ListRenderItemInfo ,
88 Dimensions ,
99 TouchableWithoutFeedback ,
10- View
10+ View ,
11+ Clipboard
1112} from 'react-native'
1213import { NavigationScreenProps , SafeAreaView } from 'react-navigation'
1314import uuid from 'uuid/v4'
@@ -84,7 +85,12 @@ interface State {
8485 showInviteContactModal : boolean
8586 showRenameGroupModal : boolean
8687 // The current selected block (message/photo). For use in the block action sheet
87- selectedBlockId ?: string
88+ selected ?: {
89+ blockId : string
90+ isCopyable : boolean
91+ canRemove : boolean
92+ text ?: string
93+ }
8894}
8995
9096class Group extends React . PureComponent < Props , State > {
@@ -157,7 +163,15 @@ class Group extends React.PureComponent<Props, State> {
157163 ]
158164 const threadCancelButtonIndex = threadActionSheetOptions . indexOf ( 'Cancel' )
159165 // Block action sheet
160- const blockActionSheetOptions = [ 'Remove' , 'Cancel' ]
166+ const blockActionSheetOptions = [
167+ ...( this . state . selected && this . state . selected . canRemove
168+ ? [ 'Remove' ]
169+ : [ ] ) ,
170+ ...( this . state . selected && this . state . selected . isCopyable
171+ ? [ 'Copy' ]
172+ : [ ] ) ,
173+ 'Cancel'
174+ ]
161175 const blockCancelButtonIndex = blockActionSheetOptions . indexOf ( 'Cancel' )
162176 return (
163177 < SafeAreaView style = { { flex : 1 , flexGrow : 1 } } >
@@ -265,9 +279,13 @@ class Group extends React.PureComponent<Props, State> {
265279 id : comment . id ,
266280 username : comment . user . name || '?' ,
267281 body : comment . body ,
268- onLongPress : canRemoveComment
269- ? ( ) => this . showBlockActionSheet ( comment . id )
270- : undefined
282+ onLongPress : ( ) =>
283+ this . showBlockActionSheet (
284+ comment . id ,
285+ canRemoveComment ,
286+ true ,
287+ comment . body
288+ )
271289 }
272290 }
273291 )
@@ -312,7 +330,7 @@ class Group extends React.PureComponent<Props, State> {
312330 pinchHeight = { pinchHeight }
313331 onLongPress = {
314332 canRemove
315- ? ( ) => this . showBlockActionSheet ( item . block )
333+ ? ( ) => this . showBlockActionSheet ( item . block , true , false )
316334 : undefined
317335 }
318336 />
@@ -341,8 +359,14 @@ class Group extends React.PureComponent<Props, State> {
341359 const avatar = isSameUser ? undefined : user . avatar
342360 return (
343361 < TouchableWithoutFeedback
344- disabled = { ! canRemove }
345- onLongPress = { ( ) => this . showBlockActionSheet ( item . block ) }
362+ onLongPress = { ( ) =>
363+ this . showBlockActionSheet (
364+ item . block ,
365+ canRemove ,
366+ true ,
367+ item . value . body
368+ )
369+ }
346370 >
347371 < View >
348372 < Message
@@ -399,9 +423,19 @@ class Group extends React.PureComponent<Props, State> {
399423 this . threadActionSheet . show ( )
400424 }
401425
402- showBlockActionSheet = ( blockId : string ) => {
426+ showBlockActionSheet = (
427+ blockId : string ,
428+ canRemove : boolean ,
429+ isCopyable : boolean ,
430+ text ?: string
431+ ) => {
403432 this . setState ( {
404- selectedBlockId : blockId
433+ selected : {
434+ blockId,
435+ canRemove,
436+ isCopyable,
437+ text
438+ }
405439 } )
406440 this . blockActionSheet . show ( )
407441 }
@@ -421,9 +455,25 @@ class Group extends React.PureComponent<Props, State> {
421455
422456 handleBlockActionSheetResponse = ( index : number ) => {
423457 const actions = [
424- ( ) =>
425- this . state . selectedBlockId &&
426- this . props . remove ( this . state . selectedBlockId )
458+ ...( this . state . selected && this . state . selected . canRemove
459+ ? [
460+ ( ) =>
461+ this . state . selected &&
462+ this . props . remove ( this . state . selected . blockId )
463+ ]
464+ : [ ] ) ,
465+ ...( this . state . selected && this . state . selected . isCopyable
466+ ? [
467+ ( ) => {
468+ if (
469+ this . state . selected &&
470+ this . state . selected . text !== undefined
471+ ) {
472+ Clipboard . setString ( this . state . selected . text )
473+ }
474+ }
475+ ]
476+ : [ ] )
427477 ]
428478 if ( index < actions . length ) {
429479 actions [ index ] ( )
0 commit comments