Skip to content

Commit

Permalink
flow: Annotate some more exported React components.
Browse files Browse the repository at this point in the history
This is much easier to do now that we've converted these to function
components in this series.

This will help move us along toward Flow's new "Types-First" mode;
switching entirely is #4907.

Prefer the `Node` type exported from React over `React$Node`.
They're equivalent, but Greg prefers `Node` as it seems cleaner; see
  https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Flow.20types-first/near/1239060.
  • Loading branch information
chrisbobbe authored and gnprice committed Jul 28, 2021
1 parent 6650e6e commit 81a50bb
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/animation/AnimatedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Props = $ReadOnly<{|
/**
* Animates the specified style property on visibility change.
*/
export default function AnimatedComponent(props: Props) {
export default function AnimatedComponent(props: Props): Node {
const {
visible = true,
useNativeDriver = true,
Expand Down
3 changes: 2 additions & 1 deletion src/autocomplete/AutocompleteView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useCallback } from 'react';
import type { Node } from 'react';

import type { InputSelection } from '../types';
import getAutocompletedText from './getAutocompletedText';
Expand Down Expand Up @@ -31,7 +32,7 @@ type Props = $ReadOnly<{|
onAutocomplete: (input: string, completion: string, lastWordPrefix: string) => void,
|}>;

export default function AutocompleteView(props: Props) {
export default function AutocompleteView(props: Props): Node {
const { isFocused, text, onAutocomplete, selection } = props;

const handleAutocomplete = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion src/common/ComponentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Props = $ReadOnly<{|
* @prop [style] - Style of the wrapper container.
* @prop [itemStyle] - Style applied to each child.
*/
export default function ComponentList(props: Props) {
export default function ComponentList(props: Props): Node {
const { children, itemStyle, spacing = 16, outerSpacing = true, style } = props;
const outerStyle = outerSpacing ? { margin: spacing } : {};
const marginStyle = { marginBottom: spacing };
Expand Down
2 changes: 1 addition & 1 deletion src/common/ComponentWithOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Props = $ReadOnly<{|
* @prop overlayPosition - What corner to align the overlay to.
* @prop [style] - Applied to a wrapper View.
*/
export default function ComponentWithOverlay(props: Props) {
export default function ComponentWithOverlay(props: Props): Node {
const {
children,
style,
Expand Down
3 changes: 2 additions & 1 deletion src/common/Input.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useState, useCallback, useContext } from 'react';
import type { Node } from 'react';
import { TextInput, Platform } from 'react-native';

import type { LocalizableText } from '../types';
Expand Down Expand Up @@ -45,7 +46,7 @@ const componentStyles = createStyleSheet({
* @prop ...all other TextInput props - Passed through verbatim to TextInput.
* See upstream: https://reactnative.dev/docs/textinput
*/
export default function Input(props: Props) {
export default function Input(props: Props): Node {
const { style, placeholder, textInputRef, ...restProps } = props;

const [isFocused, setIsFocused] = useState<boolean>(false);
Expand Down
3 changes: 2 additions & 1 deletion src/common/InputWithClearButton.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useRef, useState, useCallback } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';

import Input from './Input';
Expand All @@ -22,7 +23,7 @@ type Props = $ReadOnly<$Diff<InputProps, {| textInputRef: mixed, value: mixed, _
*
* All props are passed through to `Input`. See `Input` for descriptions.
*/
export default function InputWithClearButton(props: Props) {
export default function InputWithClearButton(props: Props): Node {
const { onChangeText } = props;

const [text, setText] = useState<string>('');
Expand Down
3 changes: 2 additions & 1 deletion src/common/LineSeparator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useContext } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';

import { ThemeContext, createStyleSheet } from '../styles';
Expand All @@ -11,7 +12,7 @@ const componentStyles = createStyleSheet({
},
});

export default function LineSeparator(props: {||}) {
export default function LineSeparator(props: {||}): Node {
const themeContext = useContext(ThemeContext);
return (
<View style={[componentStyles.lineSeparator, { backgroundColor: themeContext.cardColor }]} />
Expand Down
3 changes: 2 additions & 1 deletion src/common/LoadingIndicator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React from 'react';
import type { Node } from 'react';
import { Image, View } from 'react-native';

import SpinningProgress from './SpinningProgress';
Expand Down Expand Up @@ -36,7 +37,7 @@ type Props = $ReadOnly<{|
* @prop [showLogo] - Show or not a Zulip logo in the center.
* @prop [size] - Diameter of the indicator in pixels.
*/
export default function LoadingIndicator(props: Props) {
export default function LoadingIndicator(props: Props): Node {
const { color = 'default', showLogo = false, size = 40 } = props;

return (
Expand Down
3 changes: 2 additions & 1 deletion src/common/NestedNavRow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useContext } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';

import Label from './Label';
Expand All @@ -22,7 +23,7 @@ type Props = $ReadOnly<{|
* Shows a right-facing arrow to indicate its purpose. If you need a
* selectable option row instead, use `SelectableOptionRow`.
*/
export default function NestedNavRow(props: Props) {
export default function NestedNavRow(props: Props): Node {
const { label, onPress, Icon } = props;

const themeContext = useContext(ThemeContext);
Expand Down
3 changes: 2 additions & 1 deletion src/common/OptionDivider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useContext } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';

import { ThemeContext, createStyleSheet } from '../styles';
Expand All @@ -10,7 +11,7 @@ const componentStyles = createStyleSheet({
},
});

export default function OptionDivider(props: {||}) {
export default function OptionDivider(props: {||}): Node {
const themeContext = useContext(ThemeContext);
return (
<View style={[componentStyles.divider, { borderBottomColor: themeContext.dividerColor }]} />
Expand Down
3 changes: 2 additions & 1 deletion src/common/PasswordInput.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useState, useCallback } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';

import Input from './Input';
Expand Down Expand Up @@ -35,7 +36,7 @@ type Props = $ReadOnly<$Diff<InputProps,
*
* All props are passed through to `Input`. See `Input` for descriptions.
*/
export default function PasswordInput(props: Props) {
export default function PasswordInput(props: Props): Node {
const [isHidden, setIsHidden] = useState<boolean>(true);

const handleShow = useCallback(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/common/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Props = $ReadOnly<{|
children: Node,
|}>;

export default function Popup(props: Props) {
export default function Popup(props: Props): Node {
const themeContext = useContext(ThemeContext);
return (
<View style={[{ backgroundColor: themeContext.backgroundColor }, styles.popup]}>
Expand Down
3 changes: 2 additions & 1 deletion src/common/SearchInput.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React from 'react';
import type { Node } from 'react';
import { View } from 'react-native';
import InputWithClearButton from './InputWithClearButton';
import { createStyleSheet } from '../styles';
Expand Down Expand Up @@ -29,7 +30,7 @@ type Props = $ReadOnly<{|
* @prop [autoFocus] - should the component be focused when mounted.
* @prop onChangeText - Event called when search query is edited.
*/
export default function SearchInput(props: Props) {
export default function SearchInput(props: Props): Node {
const { autoFocus = true, onChangeText } = props;

return (
Expand Down
3 changes: 2 additions & 1 deletion src/common/SmartUrlInput.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useState, useRef, useCallback, useContext } from 'react';
import type { Node } from 'react';
import { TextInput, TouchableWithoutFeedback, View } from 'react-native';
import { useFocusEffect } from '@react-navigation/native';
import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';
Expand Down Expand Up @@ -54,7 +55,7 @@ type Props = $ReadOnly<{|
enablesReturnKeyAutomatically: boolean,
|}>;

export default function SmartUrlInput(props: Props) {
export default function SmartUrlInput(props: Props): Node {
const {
defaultProtocol,
defaultOrganization,
Expand Down
3 changes: 2 additions & 1 deletion src/common/SwitchRow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useContext } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';
import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';

Expand All @@ -25,7 +26,7 @@ const componentStyles = createStyleSheet({
/**
* A row with a label and a switch component.
*/
export default function SwitchRow(props: Props) {
export default function SwitchRow(props: Props): Node {
const { label, value, onValueChange, style, Icon } = props;

const themeContext = useContext(ThemeContext);
Expand Down
3 changes: 2 additions & 1 deletion src/common/UnreadCount.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React from 'react';
import type { Node } from 'react';
import { Text, View } from 'react-native';
import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';

Expand Down Expand Up @@ -54,7 +55,7 @@ type Props = $ReadOnly<{|
* @prop [inverse] - Indicate if styling should be inverted (dark on light).
* @prop [limited] - If set values over 100 will display as `99+`.
*/
export default function UnreadCount(props: Props) {
export default function UnreadCount(props: Props): Node {
const {
style,
isMuted = false,
Expand Down
3 changes: 2 additions & 1 deletion src/common/ZulipButton.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React from 'react';
import type { Node } from 'react';
import { Text, View, ActivityIndicator } from 'react-native';
import type { TextStyle, ViewStyle } from 'react-native/Libraries/StyleSheet/StyleSheet';
import TranslatedText from './TranslatedText';
Expand Down Expand Up @@ -121,7 +122,7 @@ type Props = $ReadOnly<{|
* @prop [secondary] - Less prominent styling, the button is not as important.
* @prop onPress - Event called on button press.
*/
export default function ZulipButton(props: Props) {
export default function ZulipButton(props: Props): Node {
const {
style,
text,
Expand Down
3 changes: 2 additions & 1 deletion src/common/ZulipSwitch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React from 'react';
import type { Node } from 'react';
import { Switch } from 'react-native';
// $FlowFixMe[untyped-import]
import Color from 'color';
Expand All @@ -19,7 +20,7 @@ type Props = $ReadOnly<{|
* @prop value - value of the switch.
* @prop onValueChange - Event called on switch.
*/
export default function ZulipSwitch(props: Props) {
export default function ZulipSwitch(props: Props): Node {
const { disabled = false, onValueChange, value } = props;
return (
<Switch
Expand Down
3 changes: 2 additions & 1 deletion src/emoji/EmojiRow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useCallback } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';

import type { EmojiType } from '../types';
Expand All @@ -25,7 +26,7 @@ type Props = $ReadOnly<{|
onPress: (name: string) => void,
|}>;

export default function EmojiRow(props: Props) {
export default function EmojiRow(props: Props): Node {
const { code, name, type, onPress } = props;

const handlePress = useCallback(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/nav/NavButtonGeneral.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const componentStyles = createStyleSheet({
},
});

export default function NavButtonGeneral(props: Props) {
export default function NavButtonGeneral(props: Props): Node {
const { children, onPress, accessibilityLabel } = props;

return (
Expand Down
3 changes: 2 additions & 1 deletion src/streams/StreamList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React from 'react';
import type { Node } from 'react';
import { SectionList } from 'react-native';

import type { Stream, Subscription } from '../types';
Expand Down Expand Up @@ -46,7 +47,7 @@ type Props = $ReadOnly<{|
onSwitch?: (streamName: string, newValue: boolean) => void,
|}>;

export default function StreamList(props: Props) {
export default function StreamList(props: Props): Node {
const {
streams = [],
showDescriptions = false,
Expand Down
3 changes: 2 additions & 1 deletion src/user-groups/UserGroupItem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useCallback, useContext } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';

import { IconPeople } from '../common/Icons';
Expand All @@ -25,7 +26,7 @@ type Props = $ReadOnly<{|
onPress: (name: string) => void,
|}>;

export default function UserGroupItem(props: Props) {
export default function UserGroupItem(props: Props): Node {
const { name, description, onPress } = props;

const handlePress = useCallback(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/users/UsersScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useState } from 'react';
import type { Node } from 'react';

import type { RouteProp } from '../react-navigation';
import type { AppNavigationProp } from '../nav/AppNavigator';
Expand All @@ -11,7 +12,7 @@ type Props = $ReadOnly<{|
route: RouteProp<'users', void>,
|}>;

export default function UsersScreen(props: Props) {
export default function UsersScreen(props: Props): Node {
const [filter, setFilter] = useState<string>('');

return (
Expand Down

0 comments on commit 81a50bb

Please sign in to comment.