Skip to content

Commit f7e37b6

Browse files
committed
Address warnings in ScanModal
1 parent 454b2f2 commit f7e37b6

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

src/components/modals/ScanModal.tsx

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { checkAndRequestPermission } from '../services/PermissionsManager'
3535
import { cacheStyles, type Theme, useTheme } from '../services/ThemeContext'
3636
import { EdgeText, Paragraph } from '../themed/EdgeText'
3737
import { ModalFooter } from '../themed/ModalParts'
38-
import { SceneHeader } from '../themed/SceneHeader'
38+
import { SceneHeaderUi4 } from '../themed/SceneHeaderUi4'
3939
import { EdgeModal } from './EdgeModal'
4040

4141
interface Props {
@@ -52,7 +52,7 @@ interface Props {
5252
textModalTitle?: string
5353
}
5454

55-
export const ScanModal = (props: Props) => {
55+
export const ScanModal: React.FC<Props> = props => {
5656
const {
5757
bridge,
5858
textModalAutoFocus,
@@ -79,34 +79,32 @@ export const ScanModal = (props: Props) => {
7979
const [torchEnabled, setTorchEnabled] = React.useState(false)
8080
const [scanEnabled, setScanEnabled] = React.useState(false)
8181

82-
const handleFlash = () => {
82+
const handleFlash = (): void => {
8383
triggerHaptic('impactLight')
8484
setTorchEnabled(!torchEnabled)
8585
}
8686

8787
// Mount effects
8888
React.useEffect(() => {
8989
setScanEnabled(true)
90-
checkAndRequestPermission('camera').catch(err => {
91-
showError(err)
92-
})
90+
checkAndRequestPermission('camera').catch(showError)
9391
return () => {
9492
setScanEnabled(false)
9593
}
9694
}, [])
9795

98-
const handleBarCodeRead = (codes: Code[]) => {
96+
const handleBarCodeRead = (codes: Code[]): void => {
9997
setScanEnabled(false)
10098
triggerHaptic('impactLight')
10199
bridge.resolve(codes[0].value)
102100
}
103101

104-
const handleSettings = async () => {
102+
const handleSettings = async (): Promise<void> => {
105103
triggerHaptic('impactLight')
106104
await Linking.openSettings()
107105
}
108106

109-
const handleTextInput = async () => {
107+
const handleTextInput = async (): Promise<void> => {
110108
triggerHaptic('impactLight')
111109
const uri = await Airship.show<string | undefined>(bridge => (
112110
<TextInputModal
@@ -124,16 +122,16 @@ export const ScanModal = (props: Props) => {
124122
}
125123
}
126124

127-
const handleAlbum = () => {
125+
const handleAlbum = (): void => {
128126
triggerHaptic('impactLight')
129127
launchImageLibrary(
130128
{
131129
mediaType: 'photo'
132130
},
133131
result => {
134-
if (result.didCancel) return
132+
if (result.didCancel === true) return
135133

136-
if (result.errorMessage) {
134+
if (result.errorMessage != null && result.errorMessage !== '') {
137135
showDevError(result.errorMessage)
138136
return
139137
}
@@ -157,18 +155,14 @@ export const ScanModal = (props: Props) => {
157155
logActivity(`QR code read from photo library.`)
158156
bridge.resolve(response.values[0])
159157
})
160-
.catch(error => {
161-
showDevError(error)
162-
})
158+
.catch(showDevError)
163159
}
164-
).catch(err => {
165-
showError(err)
166-
})
160+
).catch(showError)
167161
}
168162

169-
const handleClose = () => {
163+
const handleClose = (): void => {
170164
triggerHaptic('impactLight')
171-
// @ts-expect-error
165+
// @ts-expect-error - AirshipBridge expects string | undefined but resolve() with no args is valid
172166
bridge.resolve()
173167
}
174168

@@ -186,7 +180,7 @@ export const ScanModal = (props: Props) => {
186180
headerContainerLayout.height +
187181
(peepholeSpaceLayout.height - holeSize) / 2
188182

189-
const renderModalContent = () => {
183+
const renderModalContent = (): React.JSX.Element | null => {
190184
if (!scanEnabled) {
191185
return null
192186
}
@@ -223,7 +217,9 @@ export const ScanModal = (props: Props) => {
223217
style={styles.headerContainer}
224218
onLayout={handleLayoutHeaderContainer}
225219
>
226-
<SceneHeader title={scanModalTitle} underline withTopMargin />
220+
{/* This isn't technically a scene, so just using SceneHeaderUi4 directly for simplicity. */}
221+
{/* eslint-disable-next-line @typescript-eslint/no-deprecated */}
222+
<SceneHeaderUi4 title={scanModalTitle} />
227223
</View>
228224
<View
229225
style={[
@@ -340,8 +336,8 @@ const getStyles = cacheStyles((theme: Theme) => ({
340336
},
341337
headerContainer: {
342338
justifyContent: 'flex-end',
343-
marginBottom: theme.rem(0.5),
344-
marginTop: theme.rem(1)
339+
marginTop: theme.rem(2),
340+
marginLeft: theme.rem(0.5)
345341
},
346342
peepholeSpace: {
347343
flex: 2

0 commit comments

Comments
 (0)