diff --git a/src/common/Input.js b/src/common/Input.js index ccc041de2dc..d4c488aaa91 100644 --- a/src/common/Input.js +++ b/src/common/Input.js @@ -11,7 +11,12 @@ export type Props = $ReadOnly<{| ...React$ElementConfig, placeholder: LocalizableText, onChangeText?: (text: string) => void, - textInputRef?: React$Ref, + + // We should replace the fixme with + // `React$ElementRef` when we can. Currently, that + // would make `.current` be `any(implicit)`, which we don't want; + // this is probably down to bugs in Flow's special support for React. + textInputRef?: React$Ref<$FlowFixMe>, _: GetText, |}>; diff --git a/src/common/InputWithClearButton.js b/src/common/InputWithClearButton.js index 334082890a8..acfd53f36ef 100644 --- a/src/common/InputWithClearButton.js +++ b/src/common/InputWithClearButton.js @@ -1,6 +1,6 @@ /* @flow strict-local */ import React, { PureComponent } from 'react'; -import { View, TextInput } from 'react-native'; +import { View } from 'react-native'; import Input from './Input'; import type { Props as InputProps } from './Input'; @@ -32,7 +32,11 @@ export default class InputWithClearButton extends PureComponent { canBeCleared: false, text: '', }; - textInputRef = React.createRef(); + // We should replace the fixme with + // `React$ElementRef` when we can. Currently, that + // would make `.current` be `any(implicit)`, which we don't want; + // this is probably down to bugs in Flow's special support for React. + textInputRef = React.createRef<$FlowFixMe>(); handleChangeText = (text: string) => { this.setState({ @@ -47,9 +51,7 @@ export default class InputWithClearButton extends PureComponent { handleClear = () => { this.handleChangeText(''); if (this.textInputRef.current) { - // Should be fixed in RN v0.63 (#4245); see - // https://github.com/zulip/zulip-mobile/issues/4245#issuecomment-695104351. - // $FlowFixMe + // `.current` is not type-checked; see definition. this.textInputRef.current.clear(); } }; diff --git a/src/common/SmartUrlInput.js b/src/common/SmartUrlInput.js index e07adc53571..ddc832db3d1 100644 --- a/src/common/SmartUrlInput.js +++ b/src/common/SmartUrlInput.js @@ -69,15 +69,19 @@ export default class SmartUrlInput extends PureComponent { state = { value: '', }; - textInputRef = React.createRef(); + + // We should replace the fixme with + // `React$ElementRef` when we can. Currently, that + // would make `.current` be `any(implicit)`, which we don't want; + // this is probably down to bugs in Flow's special support for React. + textInputRef = React.createRef<$FlowFixMe>(); + unsubscribeFocusListener: () => void; componentDidMount() { this.unsubscribeFocusListener = this.props.navigation.addListener('focus', () => { if (this.textInputRef.current) { - // Should be fixed in RN v0.63 (#4245); see - // https://github.com/zulip/zulip-mobile/issues/4245#issuecomment-695104351. - // $FlowFixMe + // `.current` is not type-checked; see definition. this.textInputRef.current.focus(); } }); @@ -99,13 +103,11 @@ export default class SmartUrlInput extends PureComponent { urlPress = () => { const { textInputRef } = this; if (textInputRef.current) { - // Should be fixed in RN v0.63 (#4245); see - // https://github.com/zulip/zulip-mobile/issues/4245#issuecomment-695104351. - // $FlowFixMe + // `.current` is not type-checked; see definition. textInputRef.current.blur(); setTimeout(() => { if (textInputRef.current) { - // $FlowFixMe - same as above + // `.current` is not type-checked; see definition. textInputRef.current.focus(); } }, 100); diff --git a/src/compose/ComposeBox.js b/src/compose/ComposeBox.js index 962aa570931..ca749404048 100644 --- a/src/compose/ComposeBox.js +++ b/src/compose/ComposeBox.js @@ -1,6 +1,6 @@ /* @flow strict-local */ import React, { PureComponent } from 'react'; -import { Platform, View, TextInput, findNodeHandle } from 'react-native'; +import { Platform, View, findNodeHandle } from 'react-native'; import type { LayoutEvent } from 'react-native/Libraries/Types/CoreEventTypes'; import TextInputReset from 'react-native-text-input-reset'; import { type EdgeInsets } from 'react-native-safe-area-context'; @@ -114,9 +114,7 @@ const updateTextInput = (textInput, text) => { return; } - // Should be fixed in RN v0.63 (#4245); see - // https://github.com/zulip/zulip-mobile/issues/4245#issuecomment-695104351. - // $FlowFixMe + // `textInput` is untyped; see definition. textInput.setNativeProps({ text }); if (text.length === 0 && TextInputReset) { @@ -130,8 +128,12 @@ class ComposeBox extends PureComponent { static contextType = ThemeContext; context: ThemeData; - messageInputRef = React.createRef(); - topicInputRef = React.createRef(); + // We should replace the fixme with + // `React$ElementRef` when we can. Currently, that + // would make `.current` be `any(implicit)`, which we don't want; + // this is probably down to bugs in Flow's special support for React. + messageInputRef = React.createRef<$FlowFixMe>(); + topicInputRef = React.createRef<$FlowFixMe>(); // TODO: Type-check this, once we've adjusted our `react-redux` // wrapper to do the right thing. It should be @@ -349,9 +351,7 @@ class ComposeBox extends PureComponent { } completeEditMessage(); if (this.messageInputRef.current !== null) { - // Should be fixed in RN v0.63 (#4245); see - // https://github.com/zulip/zulip-mobile/issues/4245#issuecomment-695104351. - // $FlowFixMe + // `.current` is not type-checked; see definition. this.messageInputRef.current.blur(); } }; @@ -366,9 +366,7 @@ class ComposeBox extends PureComponent { this.setMessageInputValue(message); this.setTopicInputValue(topic); if (this.messageInputRef.current !== null) { - // Should be fixed in RN v0.63 (#4245); see - // https://github.com/zulip/zulip-mobile/issues/4245#issuecomment-695104351. - // $FlowFixMe + // `.current` is not type-checked; see definition. this.messageInputRef.current.focus(); } }