Skip to content

Commit 647b9a2

Browse files
authored
HEIC fe changes (keybase#26358)
1 parent c4b9350 commit 647b9a2

9 files changed

Lines changed: 150 additions & 142 deletions

File tree

‎shared/chat/conversation/attachment-get-titles/index.tsx‎

Lines changed: 105 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as Kb from '@/common-adapters'
33
import * as Styles from '@/styles'
44
import * as C from '@/constants'
55
import type * as T from '@/constants/types'
6+
import {isPathHEIC} from '@/constants/chat2'
67

78
export type Info = {
89
type: 'image' | 'file' | 'video'
@@ -24,140 +25,126 @@ type Props = {
2425
onSubmit: (titles: Array<string>, spoiler: boolean) => void
2526
}
2627

27-
type State = {
28-
index: number
29-
titles: Array<string>
30-
spoiler: boolean
31-
}
32-
33-
class GetTitles extends React.Component<Props, State> {
34-
state: State
35-
36-
constructor(props: Props) {
37-
super(props)
38-
this.state = {
39-
index: 0,
40-
spoiler: false,
41-
titles: props.pathAndInfos.map((_, idx) => props.titles?.[idx] ?? ''),
42-
}
43-
}
28+
const GetTitles = (p: Props) => {
29+
const {pathAndInfos, titles: _titles, onSubmit: _onSubmit, onCancel} = p
30+
const [index, setIndex] = React.useState(0)
31+
const [titles, setTitles] = React.useState(pathAndInfos.map((_, idx) => _titles?.[idx] ?? ''))
32+
const [spoiler, setSpoiler] = React.useState(false)
33+
setSpoiler // TODO commented out
4434

45-
_onNext = (e?: React.BaseSyntheticEvent) => {
46-
e?.preventDefault()
35+
const onNext = React.useCallback(
36+
(e?: React.BaseSyntheticEvent) => {
37+
e?.preventDefault()
4738

48-
const {info} = this.props.pathAndInfos[this.state.index] ?? {}
49-
if (!info) return
39+
const {info} = pathAndInfos[index] ?? {}
40+
if (!info) return
5041

51-
const nextIndex = this.state.index + 1
42+
const nextIndex = index + 1
5243

53-
// done
54-
if (nextIndex === this.props.pathAndInfos.length) {
55-
this.props.onSubmit(this.state.titles, this.state.spoiler)
56-
} else {
57-
// go to next
58-
this.setState({index: nextIndex})
44+
// done
45+
if (nextIndex === pathAndInfos.length) {
46+
_onSubmit(titles, spoiler)
47+
} else {
48+
// go to next
49+
setIndex(s => s + 1)
50+
}
51+
},
52+
[index, pathAndInfos, titles, spoiler, setIndex, _onSubmit]
53+
)
54+
55+
const onSubmit = React.useCallback(
56+
(e?: React.BaseSyntheticEvent) => {
57+
e?.preventDefault()
58+
_onSubmit(titles, spoiler)
59+
},
60+
[_onSubmit, titles, spoiler]
61+
)
62+
63+
const updateTitle = React.useCallback(
64+
(title: string) => {
65+
setTitles([...titles.slice(0, index), title, ...titles.slice(index + 1)])
66+
},
67+
[index, titles]
68+
)
69+
70+
const {info, path} = pathAndInfos[index] ?? {}
71+
const titleHint = 'Add a caption...'
72+
if (!info) return null
73+
74+
let preview: React.ReactNode = null
75+
switch (info.type) {
76+
case 'image':
77+
preview = path ? <Kb.ZoomableImage src={info.url ?? path} style={styles.image} /> : null
78+
break
79+
case 'video':
80+
preview = path ? <Kb.Video autoPlay={false} allowFile={true} muted={true} url={path} /> : null
81+
break
82+
default: {
83+
if (C.isIOS && path && isPathHEIC(path)) {
84+
preview = <Kb.ZoomableImage src={path} style={styles.image} />
85+
} else {
86+
preview = (
87+
<Kb.Box2 direction="vertical" fullWidth={true} fullHeight={true} centerChildren={true}>
88+
<Kb.Icon type="icon-file-uploading-48" />
89+
</Kb.Box2>
90+
)
91+
}
5992
}
6093
}
6194

62-
_onSubmit = (e?: React.BaseSyntheticEvent) => {
63-
e?.preventDefault()
64-
this.props.onSubmit(this.state.titles, this.state.spoiler)
65-
}
66-
67-
_isLast = () => {
68-
const numPaths = this.props.pathAndInfos.length
69-
return this.state.index + 1 === numPaths
70-
}
71-
95+
const isLast = index + 1 === pathAndInfos.length
7296
// Are we trying to upload multiple?
73-
_multiUpload = () => {
74-
return this.props.pathAndInfos.length > 1
75-
}
76-
77-
_updateTitle = (title: string) => {
78-
this.setState(state => ({
79-
titles: [...state.titles.slice(0, state.index), title, ...state.titles.slice(state.index + 1)],
80-
}))
81-
}
82-
83-
render() {
84-
const {info, path} = this.props.pathAndInfos[this.state.index] ?? {}
85-
const titleHint = 'Add a caption...'
86-
if (!info) return null
87-
88-
let preview: React.ReactNode = null
89-
switch (info.type) {
90-
case 'image':
91-
preview = path ? <Kb.ZoomableImage src={info.url ?? path} style={styles.image} /> : null
92-
break
93-
case 'video':
94-
preview = path ? <Kb.Video autoPlay={false} allowFile={true} muted={true} url={path} /> : null
95-
break
96-
default: {
97-
if (C.isMobile && path?.toLowerCase().endsWith('.heic')) {
98-
preview = <Kb.ZoomableImage src={path} style={styles.image} />
99-
} else {
100-
preview = (
101-
<Kb.Box2 direction="vertical" fullWidth={true} fullHeight={true} centerChildren={true}>
102-
<Kb.Icon type="icon-file-uploading-48" />
97+
const multiUpload = pathAndInfos.length > 1
98+
99+
return (
100+
<Kb.PopupWrapper onCancel={onCancel}>
101+
<Kb.Box2 direction="vertical" style={styles.containerOuter} fullWidth={true}>
102+
<Kb.Box2 alignItems="center" direction="vertical" fullWidth={true} style={styles.container}>
103+
<Kb.BoxGrow style={styles.boxGrow}>{preview}</Kb.BoxGrow>
104+
{pathAndInfos.length > 0 && !Styles.isMobile && (
105+
<Kb.Box2 direction="vertical" style={styles.filename}>
106+
<Kb.Text type="BodySmallSemibold">Filename</Kb.Text>
107+
<Kb.Text type="BodySmall" center={true}>
108+
{info.filename} ({index + 1} of {pathAndInfos.length})
109+
</Kb.Text>
103110
</Kb.Box2>
104-
)
105-
}
106-
}
107-
}
108-
109-
return (
110-
<Kb.PopupWrapper onCancel={this.props.onCancel}>
111-
<Kb.Box2 direction="vertical" style={styles.containerOuter} fullWidth={true}>
112-
<Kb.Box2 alignItems="center" direction="vertical" fullWidth={true} style={styles.container}>
113-
<Kb.BoxGrow style={styles.boxGrow}>{preview}</Kb.BoxGrow>
114-
{this.props.pathAndInfos.length > 0 && !Styles.isMobile && (
115-
<Kb.Box2 direction="vertical" style={styles.filename}>
116-
<Kb.Text type="BodySmallSemibold">Filename</Kb.Text>
117-
<Kb.Text type="BodySmall" center={true}>
118-
{info.filename} ({this.state.index + 1} of {this.props.pathAndInfos.length})
119-
</Kb.Text>
120-
</Kb.Box2>
121-
)}
122-
<Kb.Box2 direction="vertical" fullWidth={true} style={styles.inputContainer}>
123-
<Kb.PlainInput
124-
style={styles.input}
125-
autoFocus={!Styles.isMobile}
126-
autoCorrect={true}
127-
placeholder={titleHint}
128-
multiline={true}
129-
rowsMin={2}
130-
padding="tiny"
131-
value={this.state.titles[this.state.index]}
132-
onEnterKeyDown={this._onNext}
133-
onChangeText={this._updateTitle}
134-
selectTextOnFocus={true}
135-
/>
136-
{/* (
111+
)}
112+
<Kb.Box2 direction="vertical" fullWidth={true} style={styles.inputContainer}>
113+
<Kb.PlainInput
114+
style={styles.input}
115+
autoFocus={!Styles.isMobile}
116+
autoCorrect={true}
117+
placeholder={titleHint}
118+
multiline={true}
119+
rowsMin={2}
120+
padding="tiny"
121+
value={titles[index]}
122+
onEnterKeyDown={onNext}
123+
onChangeText={updateTitle}
124+
selectTextOnFocus={true}
125+
/>
126+
{/* (
137127
<Kb.Checkbox
138128
style={{alignSelf: 'flex-end'}}
139129
label="Spoiler?"
140-
checked={this.state.spoiler}
141-
onCheck={c => this.setState({spoiler: c})}
130+
checked={spoiler}
131+
onCheck={setSpoiler}
142132
/>
143133
)*/}
144-
</Kb.Box2>
145134
</Kb.Box2>
146-
<Kb.ButtonBar fullWidth={true} small={true} style={styles.buttonContainer}>
147-
{!Styles.isMobile && (
148-
<Kb.Button fullWidth={true} type="Dim" onClick={this.props.onCancel} label="Cancel" />
149-
)}
150-
{this._isLast() ? (
151-
<Kb.WaitingButton fullWidth={!this._multiUpload()} onClick={this._onSubmit} label="Send" />
152-
) : (
153-
<Kb.Button fullWidth={!this._multiUpload()} onClick={this._onNext} label="Next" />
154-
)}
155-
{this._multiUpload() ? <Kb.WaitingButton onClick={this._onSubmit} label="Send All" /> : null}
156-
</Kb.ButtonBar>
157135
</Kb.Box2>
158-
</Kb.PopupWrapper>
159-
)
160-
}
136+
<Kb.ButtonBar fullWidth={true} small={true} style={styles.buttonContainer}>
137+
{!Styles.isMobile && <Kb.Button fullWidth={true} type="Dim" onClick={onCancel} label="Cancel" />}
138+
{isLast ? (
139+
<Kb.WaitingButton fullWidth={!multiUpload} onClick={onSubmit} label="Send" />
140+
) : (
141+
<Kb.Button fullWidth={!multiUpload} onClick={onNext} label="Next" />
142+
)}
143+
{multiUpload ? <Kb.WaitingButton onClick={onSubmit} label="Send All" /> : null}
144+
</Kb.ButtonBar>
145+
</Kb.Box2>
146+
</Kb.PopupWrapper>
147+
)
161148
}
162149

163150
const styles = Styles.styleSheetCreate(

‎shared/chat/conversation/fwd-msg/team-picker.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ const TeamPicker = (props: Props) => {
6666
}
6767
break
6868
default:
69+
// heics
70+
if (C.Chat.isImageViewable(message)) {
71+
const src = message.fileURL || message.previewURL
72+
preview = src ? <Kb.ZoomableImage src={src} style={styles.image} /> : null
73+
}
6974
}
7075
}
7176

‎shared/chat/conversation/messages/message-popup/attachment.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ const PopAttach = (ownProps: OwnProps) => {
5252
const _onSaveAttachment = React.useCallback(() => {
5353
messageAttachmentNativeSave(ordinal)
5454
}, [messageAttachmentNativeSave, ordinal])
55-
const onSaveAttachment = C.isMobile && attachmentType === 'image' ? _onSaveAttachment : undefined
55+
56+
const onSaveAttachment =
57+
(C.isMobile && attachmentType === 'image') || C.Chat.isImageViewable(message)
58+
? _onSaveAttachment
59+
: undefined
5660

5761
const _onShareAttachment = React.useCallback(() => {
5862
messageAttachmentNativeShare(ordinal)

‎shared/constants/chat2/message.tsx‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,30 @@ import isEqual from 'lodash/isEqual'
1212

1313
const noString = new HiddenString('')
1414

15+
export const isPathHEIC = (path: string) => path.toLowerCase().endsWith('.heic')
16+
// real image or heic
17+
export const isImageViewable = (message: T.Chat.Message) => {
18+
if (message.type === 'attachment') {
19+
if (message.attachmentType === 'image') {
20+
// regular image
21+
return true
22+
}
23+
if (message.attachmentType === 'file' && C.isIOS && isPathHEIC(message.fileName)) {
24+
return true
25+
}
26+
}
27+
return false
28+
}
29+
1530
export const getMessageRenderType = (m: T.Immutable<T.Chat.Message>): T.Chat.RenderMessageType => {
1631
switch (m.type) {
1732
case 'attachment':
1833
if (m.inlineVideoPlayable && m.attachmentType !== 'audio') {
1934
return 'attachment:video'
2035
}
21-
if (C.isMobile) {
22-
// allow heic on mobile only
23-
if (m.attachmentType === 'file' && m.fileName.toLowerCase().endsWith('.heic')) {
24-
return 'attachment:image'
25-
}
36+
// allow heic on ios only
37+
if (isImageViewable(m)) {
38+
return 'attachment:image'
2639
}
2740
return `attachment:${m.attachmentType}`
2841
default:

‎shared/fs/common/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export {default as PathItemAction} from './path-item-action'
1+
export {default as PathItemAction, type ClickableProps} from './path-item-action'
22
export {default as OpenInSystemFileManager} from './open-in-system-file-manager'
33
export {default as LastModifiedLine} from './last-modified-line-container'
44
export {default as TlfInfoLine} from './tlf-info-line-container'

‎shared/fs/common/path-item-action/index.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as Kb from '@/common-adapters'
55
import ChooseView from './choose-view'
66
import type {SizeType} from '@/common-adapters/icon'
77

8-
type ClickableProps = {
8+
export type ClickableProps = {
99
onClick: () => void
10-
ref: React.RefObject<Kb.MeasureRef>
10+
mref: React.RefObject<Kb.MeasureRef>
1111
}
1212

1313
type ClickableComponent = {
@@ -100,7 +100,7 @@ const PathItemAction = (props: Props) => {
100100
return (
101101
<>
102102
{props.clickable.type === 'component' && (
103-
<props.clickable.component onClick={onClick} ref={popupAnchor} />
103+
<props.clickable.component onClick={onClick} mref={popupAnchor} />
104104
)}
105105
{props.clickable.type === 'icon' && (
106106
<IconClickable

‎shared/fs/filepreview/default-view.tsx‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as T from '@/constants/types'
22
import * as C from '@/constants'
33
import * as Kb from '@/common-adapters'
4-
import {PathItemAction, LastModifiedLine, ItemIcon} from '../common'
4+
import {PathItemAction, LastModifiedLine, ItemIcon, type ClickableProps} from '../common'
55
import {hasShare} from '../common/path-item-action/layout'
66

77
type DefaultViewProps = {
@@ -12,6 +12,7 @@ type DefaultViewProps = {
1212
showInSystemFileManager: () => void
1313
}
1414

15+
const Share = (p: ClickableProps) => <Kb.Button key="share" label="Share" onClick={p.onClick} ref={p.mref} />
1516
const DefaultView = (props: DefaultViewProps) => {
1617
const fileContext = C.useFSState(s => s.fileContext.get(props.path) || C.FS.emptyFileContext)
1718
return (
@@ -46,9 +47,7 @@ const DefaultView = (props: DefaultViewProps) => {
4647
<Kb.Box2 direction="vertical" gap="medium" gapStart={true} />
4748
<PathItemAction
4849
clickable={{
49-
component: ({onClick, ref}) => (
50-
<Kb.Button key="share" label="Share" onClick={onClick} ref={ref} />
51-
),
50+
component: Share,
5251
type: 'component',
5352
}}
5453
path={props.path}

‎shared/fs/filepreview/view.tsx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ const FilePreviewViewContent = ({path, onUrlError}: Props) => {
6767
const url = fileContext.url + `&unused_field_ts=${loadedLastModifiedTimestamp}`
6868
switch (fileContext.viewType) {
6969
case T.RPCGen.GUIViewType.default: {
70-
// mobile client only supports heic now, but this doesn't work, TODO
71-
// if (C.isMobile && pathItem.name.toLowerCase().endsWith('.heic')) {
72-
// return (
73-
// <>
74-
// {reloadBanner}
75-
// <Kb.ZoomableImage src={url} style={styles.zoomableBox} />
76-
// </>
77-
// )
78-
// }
70+
// mobile client only supports heic now
71+
if (C.isIOS && C.Chat.isPathHEIC(pathItem.name)) {
72+
return (
73+
<>
74+
{reloadBanner}
75+
<Kb.ZoomableImage src={url} style={styles.zoomableBox} />
76+
</>
77+
)
78+
}
7979
return <DefaultView path={path} />
8080
}
8181
case T.RPCGen.GUIViewType.text:

‎shared/todo.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ mem leak
77
f6 for just a router remount?
88

99
framepack, dispatch invocations
10-
memoize-one remove
10+
kbfs heic preview broken (at go level)

0 commit comments

Comments
 (0)