@@ -4,21 +4,22 @@ import { View, ImageBackground, ScrollView, FlatList, Text } from 'react-native'
44import type { SharingNavigationProp } from './SharingScreen' ;
55import type { RouteProp } from '../react-navigation' ;
66import * as NavigationService from '../nav/NavigationService' ;
7- import type { Dispatch , Subscription , Auth , GetText , SharedData } from '../types' ;
7+ import type { Dispatch , Subscription , Auth , GetText , SharedData , Content } from '../types' ;
88import { BRAND_COLOR , createStyleSheet } from '../styles' ;
99import { TranslationContext } from '../boot/TranslationProvider' ;
1010import { connect } from '../react-redux' ;
11- import { ZulipButton , Input } from '../common' ;
11+ import { ZulipButton , Input , ComponentWithOverlay } from '../common' ;
1212import { getSubscriptionsById } from '../subscriptions/subscriptionSelectors' ;
1313import StreamAutocomplete from '../autocomplete/StreamAutocomplete' ;
1414import TopicAutocomplete from '../autocomplete/TopicAutocomplete' ;
1515import AnimatedScaleComponent from '../animation/AnimatedScaleComponent' ;
1616import { streamNarrow } from '../utils/narrow' ;
17+ import { showToast } from '../utils/info' ;
1718import { getAuth } from '../selectors' ;
1819import { navigateBack , replaceWithChat } from '../nav/navActions' ;
1920import { fetchTopicsForStream } from '../topics/topicActions' ;
2021import { handleSend } from './send' ;
21- import { IconAttachment } from '../common/Icons' ;
22+ import { IconAttachment , IconCancel } from '../common/Icons' ;
2223
2324const styles = createStyleSheet ( {
2425 wrapper : {
@@ -50,12 +51,19 @@ const styles = createStyleSheet({
5051 left : 0 ,
5152 right : 0 ,
5253 } ,
54+ cross : {
55+ backgroundColor : '#000000a0' ,
56+ position : 'absolute' ,
57+ right : 0 ,
58+ top : 0 ,
59+ height : 20 ,
60+ width : 20 ,
61+ } ,
5362} ) ;
5463
5564type Props = $ReadOnly < { |
5665 navigation : SharingNavigationProp < 'share-to-stream' > ,
5766 route : RouteProp < 'share-to-stream' , { | sharedData : SharedData | } > ,
58-
5967 dispatch : Dispatch ,
6068 subscriptions : Map < number , Subscription > ,
6169 auth : Auth ,
@@ -68,6 +76,7 @@ type State = $ReadOnly<{|
6876 isStreamFocused : boolean ,
6977 isTopicFocused : boolean ,
7078 sending : boolean ,
79+ content : Array < Content > ,
7180| } > ;
7281
7382class ShareToStream extends React . Component < Props , State > {
@@ -81,6 +90,7 @@ class ShareToStream extends React.Component<Props, State> {
8190 isStreamFocused : false ,
8291 isTopicFocused : false ,
8392 sending : false ,
93+ content : this . props . route . params . sharedData . content || [ ] ,
8494 } ;
8595
8696 setSending = ( ) => {
@@ -136,6 +146,10 @@ class ShareToStream extends React.Component<Props, State> {
136146 const { sharedData } = this . props . route . params ;
137147 const data = { stream, topic, message, sharedData, type : 'stream' } ;
138148
149+ if ( ! sharedData . isText ) {
150+ sharedData . content = this . state . content ;
151+ }
152+
139153 this . setSending ( ) ;
140154 try {
141155 await handleSend ( data , auth , _ ) ;
@@ -166,17 +180,35 @@ class ShareToStream extends React.Component<Props, State> {
166180 return stream !== '' && topic !== '' && message !== '';
167181 } ;
168182
169- renderItem = ( { item, index, separators } ) =>
170- item . type . startsWith ( 'image' ) ? (
171- < ImageBackground source = { { uri : item . url } } style = { styles . imagePreview } >
172- < Text style = { styles . previewText } > { item . fileName } </ Text >
173- </ ImageBackground >
174- ) : (
175- < View style = { styles . imagePreview } >
176- < IconAttachment size = { 200 } color = { BRAND_COLOR } />
177- < Text style = { styles . previewText } > { item . fileName } </ Text >
178- </ View >
179- ) ;
183+ deleteItem = toDelete => {
184+ const content = [ ...this . state . content ] ;
185+ const filteredItems = content . filter ( item => item . url !== toDelete . url ) ;
186+ this . setState ( { content : filteredItems } ) ;
187+ if ( filteredItems . length === 0 ) {
188+ showToast ( 'Cancelled Share' ) ;
189+ this . finishShare ( ) ;
190+ }
191+ } ;
192+
193+ renderItem = ( { item, index, separators } ) = > (
194+ < ComponentWithOverlay
195+ overlaySize = { 20 }
196+ overlayColor = "white"
197+ overlayPosition = "bottom-right"
198+ overlay = { < IconCancel color = "gray" size = { 20 } onPress = { ( ) => this . deleteItem ( item ) } /> }
199+ >
200+ { item . type . startsWith ( 'image' ) ? (
201+ < ImageBackground source = { { uri : item . url } } style = { styles . imagePreview } >
202+ < Text style = { styles . previewText } > { item . fileName } </ Text >
203+ </ ImageBackground >
204+ ) : (
205+ < View style = { styles . imagePreview } >
206+ < IconAttachment size = { 200 } color = { BRAND_COLOR } />
207+ < Text style = { styles . previewText } > { item . fileName } </ Text >
208+ </ View >
209+ ) }
210+ </ ComponentWithOverlay >
211+ ) ;
180212
181213 render ( ) {
182214 const { sharedData } = this . props . route . params ;
@@ -191,7 +223,7 @@ class ShareToStream extends React.Component<Props, State> {
191223 < > </ >
192224 ) : (
193225 < FlatList
194- data = { sharedData . content }
226+ data = { this . state . content }
195227 renderItem = { this . renderItem }
196228 keyExtractor = { i => i . url }
197229 horizontal
0 commit comments