Skip to content

Commit 26cf92a

Browse files
committed
ZulipButton [nfc]: Limit the set of style properties allowed.
The use of specific style properties for callers to micromanage the layout of the button is pretty chaotic and fragile, introducing implicit dependencies on details of the ZulipButton implementation. It'd be good to assimilate those usages into a more coherent set of options provided by the ZulipButton interface explicitly. This would also help with making the buttons' appearance more consistent across the app. Until then, by listing here the properties we do use, we can at least make it possible when working on the ZulipButton implementation to know the scope of different ways that callers can mess with the styles.
1 parent f17afce commit 26cf92a

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/common/ZulipButton.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/* @flow strict-local */
22
import React, { PureComponent } from 'react';
33
import { Text, View, ActivityIndicator } from 'react-native';
4-
import type { TextStyleProp, ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';
4+
import type { TextStyle, ViewStyle } from 'react-native/Libraries/StyleSheet/StyleSheet';
55
import TranslatedText from './TranslatedText';
66

77
import type { LocalizableText } from '../types';
8+
import type { SubsetProperties } from '../generics';
89
import type { SpecificIconType } from './Icons';
910
import { BRAND_COLOR, createStyleSheet } from '../styles';
1011
import Touchable from './Touchable';
@@ -63,8 +64,38 @@ const styles = createStyleSheet({
6364
});
6465

6566
type Props = $ReadOnly<{|
66-
style?: ViewStyleProp,
67-
textStyle?: TextStyleProp,
67+
/* eslint-disable flowtype/generic-spacing */
68+
style?: SubsetProperties<
69+
ViewStyle,
70+
{|
71+
// The use of specific style properties for callers to micromanage the
72+
// layout of the button is pretty chaotic and fragile, introducing
73+
// implicit dependencies on details of the ZulipButton implementation.
74+
// TODO: Assimilate those usages into a more coherent set of options
75+
// provided by the ZulipButton interface explicitly.
76+
//
77+
// Until then, by listing here the properties we do use, we at least
78+
// make it possible when working on the ZulipButton implementation to
79+
// know the scope of different ways that callers can mess with the
80+
// styles. If you need one not listed here and it's in the same
81+
// spirit as others that are, feel free to add it.
82+
margin?: mixed,
83+
marginTop?: mixed,
84+
marginBottom?: mixed,
85+
marginHorizontal?: mixed,
86+
// (... e.g., go ahead and add more variations on margin.)
87+
padding?: mixed,
88+
paddingLeft?: mixed,
89+
paddingRight?: mixed,
90+
height?: mixed,
91+
width?: mixed,
92+
borderRadius?: mixed,
93+
flex?: mixed,
94+
alignSelf?: mixed,
95+
backgroundColor?: mixed,
96+
|},
97+
>,
98+
textStyle?: SubsetProperties<TextStyle, {| color?: mixed |}>,
6899
progress: boolean,
69100
disabled: boolean,
70101
Icon?: SpecificIconType,

0 commit comments

Comments
 (0)