Skip to content

Commit 634e800

Browse files
authored
ThemeManager - Adding deprecation warning for 'setTheme()'. (#961)
* ThemeManager - Adding deprecation warning for 'setTheme()'. * Removing setTheme() examples; Removing ThemeManager theme colors usage; Setting Colors.primary instead of ThemeManager.primaryColor; Moving TouchableOpacity defaultProps from ThemeManager to the component. * TouchableOpacity - replacing default props with default values
1 parent cbe7e33 commit 634e800

File tree

19 files changed

+106
-111
lines changed

19 files changed

+106
-111
lines changed

demo/src/demoApp.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import AsyncStorage from '@react-native-community/async-storage';
22
import {Navigation} from 'react-native-navigation';
33
import * as Animatable from 'react-native-animatable';
4-
import {
5-
AnimatableManager,
6-
ThemeManager,
7-
Constants,
8-
Colors,
9-
Typography
10-
} from 'react-native-ui-lib'; // eslint-disable-line
4+
import {AnimatableManager, Constants, Colors, Typography} from 'react-native-ui-lib'; // eslint-disable-line
115
import {registerScreens} from './screens';
126

7+
138
/** Examples - uncomment when needed */
149
// Typography.loadTypographies({
1510
// h1: {fontSize: 58, fontWeight: '300', lineHeight: 80},
@@ -21,16 +16,6 @@ import {registerScreens} from './screens';
2116
// gold: '#FFD700',
2217
// });
2318

24-
// ThemeManager.setTheme({
25-
// primaryColor: Colors.purple30,
26-
// CTA: {
27-
// backgroundColor: Colors.purple30,
28-
// textColor: Colors.dark10,
29-
// },
30-
// titleColor: Colors.blue10,
31-
// subtitleColor: Colors.blue40,
32-
// });
33-
3419
// ThemeManager.setComponentTheme('Picker', (props) => {
3520
// if (props.useNativePicker) {
3621
// return {
@@ -77,7 +62,7 @@ function getDefaultNavigationStyle() {
7762
statusBar: {
7863
visible: true,
7964
style: 'light',
80-
backgroundColor: ThemeManager.primaryColor // for Android
65+
backgroundColor: Colors.primary // for Android
8166
},
8267
layout: {
8368
backgroundColor: Colors.white,
@@ -88,7 +73,7 @@ function getDefaultNavigationStyle() {
8873
noBorder: true, // for iOS
8974
elevation: 0, // for Android
9075
background: {
91-
color: ThemeManager.primaryColor
76+
color: Colors.primary
9277
},
9378
title: {
9479
color: Colors.white,

demo/src/screens/animationScreens/ListAnimationsScreen.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {Component} from 'react';
22
import {Alert, StyleSheet, ScrollView, FlatList} from 'react-native';
33
import * as Animatable from 'react-native-animatable';
4-
import {AnimatableManager, ThemeManager, Colors, View, Button, ListItem, Text} from 'react-native-ui-lib';//eslint-disable-line
4+
import {AnimatableManager, Colors, View, Button, ListItem, Text} from 'react-native-ui-lib'; //eslint-disable-line
55

66

77
const listItems = [
@@ -31,7 +31,7 @@ export default class ListAnimationsScreen extends Component {
3131
entranceAnimation: true,
3232
addingAnimation: false,
3333
animation: animationType.ENTRANCE,
34-
counter: 0,
34+
counter: 0
3535
};
3636
}
3737

@@ -53,12 +53,14 @@ export default class ListAnimationsScreen extends Component {
5353
addItem() {
5454
const {items, counter} = this.state;
5555
const itemsCopy = [...items];
56+
5657
itemsCopy.splice(counter, 0, {id: `${itemsCopy.length}-new`, text: 'Item'});
5758
this.setState({items: itemsCopy, animation: animationType.ADDING});
5859
}
5960

6061
renderItem(item, index) {
6162
const {animation, counter} = this.state;
63+
6264
let animationProps;
6365
switch (animation) {
6466
case animationType.FADE_IN:
@@ -98,17 +100,17 @@ export default class ListAnimationsScreen extends Component {
98100
</View>
99101
<View row center>
100102
<Button outline size='medium' margin-10 label={`Add at index: ${counter}`} onPress={() => this.addItem()}/>
101-
<Button
102-
round outline size='large' label='+'
103+
<Button
104+
round outline size='large' label='+'
103105
onPress={() => this.setState({counter: counter < items.length ? counter + 1 : counter})}
104106
/>
105-
<Button
106-
round outline size='large' margin-10 label='-'
107+
<Button
108+
round outline size='large' margin-10 label='-'
107109
onPress={() => this.setState({counter: counter !== 0 ? counter - 1 : 0})}
108110
/>
109111
</View>
110112
<ScrollView style={{flex: 1}}>
111-
{visible &&
113+
{visible &&
112114
<FlatList
113115
data={items}
114116
renderItem={({item, index}) => this.renderItem(item, index)}
@@ -125,6 +127,6 @@ const styles = StyleSheet.create({
125127
paddingHorizontal: 20,
126128
backgroundColor: Colors.dark60,
127129
borderBottomWidth: 2,
128-
borderColor: ThemeManager.dividerColor,
129-
},
130+
borderColor: Colors.dark70
131+
}
130132
});

demo/src/screens/componentScreens/BasicListScreen.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import React, {Component} from 'react';
22
import {StyleSheet, Alert, FlatList} from 'react-native';
33
import * as Animatable from 'react-native-animatable';
4-
import {AnimatableManager, ThemeManager, Colors, BorderRadiuses, ListItem, Text} from 'react-native-ui-lib'; //eslint-disable-line
4+
import {AnimatableManager, Colors, BorderRadiuses, ListItem, Text} from 'react-native-ui-lib'; //eslint-disable-line
55
import orders from '../../data/orders';
66

77

88
export default class BasicListScreen extends Component {
99

1010
constructor(props) {
1111
super(props);
12-
12+
1313
this.state = {
1414
onEdit: false,
15-
updating: false,
15+
updating: false
1616
};
1717
}
1818

@@ -69,10 +69,10 @@ const styles = StyleSheet.create({
6969
width: 54,
7070
height: 54,
7171
borderRadius: BorderRadiuses.br20,
72-
marginHorizontal: 14,
72+
marginHorizontal: 14
7373
},
7474
border: {
7575
borderBottomWidth: StyleSheet.hairlineWidth,
76-
borderColor: ThemeManager.dividerColor,
77-
},
76+
borderColor: Colors.dark70
77+
}
7878
});

demo/src/screens/componentScreens/ContactsListScreen.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {Component} from 'react';
22
import {StyleSheet, Alert, FlatList} from 'react-native';
33
import {View as AnimatableView} from 'react-native-animatable';
4-
import {AnimatableManager, Colors, ThemeManager, ListItem, Text, Avatar, AvatarHelper} from 'react-native-ui-lib'; //eslint-disable-line
4+
import {AnimatableManager, Colors, ListItem, Text, Avatar, AvatarHelper} from 'react-native-ui-lib'; //eslint-disable-line
55
import conversations from '../../data/conversations';
66

77

@@ -12,7 +12,7 @@ export default class ContactsListScreen extends Component {
1212

1313
this.state = {
1414
onEdit: false,
15-
updating: false,
15+
updating: false
1616
};
1717
}
1818

@@ -58,6 +58,6 @@ export default class ContactsListScreen extends Component {
5858
const styles = StyleSheet.create({
5959
border: {
6060
borderBottomWidth: StyleSheet.hairlineWidth,
61-
borderColor: ThemeManager.dividerColor,
62-
},
61+
borderColor: Colors.dark70
62+
}
6363
});

demo/src/screens/componentScreens/ConversationListScreen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import React, {Component, PureComponent} from 'react';
44
import {StyleSheet, Alert, FlatList} from 'react-native';
55
import {gestureHandlerRootHOC} from 'react-native-gesture-handler';
6-
import {ThemeManager, Colors, ListItem, Text, Avatar, AvatarHelper, Drawer, Button} from 'react-native-ui-lib'; //eslint-disable-line
6+
import {Colors, ListItem, Text, Avatar, AvatarHelper, Drawer, Button} from 'react-native-ui-lib'; //eslint-disable-line
77
import conversations from '../../data/conversations';
88

99

@@ -174,7 +174,7 @@ class ContactItem extends PureComponent {
174174
const styles = StyleSheet.create({
175175
border: {
176176
borderBottomWidth: StyleSheet.hairlineWidth,
177-
borderColor: ThemeManager.dividerColor,
177+
borderColor: Colors.dark70,
178178
paddingRight: 17
179179
},
180180
avatar: {

src/components/badge/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import {ImageSourcePropType, ImageStyle, StyleProp, StyleSheet, Text, TextStyle,
44
import {View as AnimatableView} from 'react-native-animatable';
55
import {extractAccessibilityProps, extractAnimationProps} from '../../commons/modifiers';
66
import {asBaseComponent} from '../../commons/new';
7-
import {BorderRadiuses, Colors, ThemeManager, Typography} from '../../style';
8-
import Image from '../image';
7+
import {BorderRadiuses, Colors, Typography} from '../../style';
98
import TouchableOpacity from '../touchableOpacity';
9+
import Image from '../image';
1010
import View from '../view';
1111

12+
1213
const LABEL_FORMATTER_VALUES = [1, 2, 3, 4] as const;
1314

1415
// TODO: depreciate enum badge sizes, use only number for size
@@ -276,7 +277,7 @@ function createStyles(props: BadgeProps) {
276277
badge: {
277278
alignSelf: 'flex-start',
278279
borderRadius: BorderRadiuses.br100,
279-
backgroundColor: !props.icon ? ThemeManager.primaryColor : undefined,
280+
backgroundColor: !props.icon ? Colors.primary : undefined,
280281
alignItems: 'center',
281282
justifyContent: 'center',
282283
overflow: 'hidden'

src/components/button/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import _ from 'lodash';
12
import React, {PureComponent} from 'react';
23
import {Platform, StyleSheet, LayoutAnimation, LayoutChangeEvent, ImageStyle, TextStyle, StyleProp} from 'react-native';
3-
import _ from 'lodash';
44
import {
55
asBaseComponent,
66
forwardRef,
@@ -13,7 +13,7 @@ import {
1313
} from '../../commons/new';
1414
//@ts-ignore
1515
import {Constants} from '../../helpers';
16-
import {Colors, Typography, ThemeManager, BorderRadiuses} from '../../style';
16+
import {Colors, Typography, BorderRadiuses} from '../../style';
1717
import {extractColorValue, extractTypographyValue} from '../../commons/modifiers';
1818
import TouchableOpacity, {TouchableOpacityProps} from '../touchableOpacity';
1919
import Text, {TextPropTypes} from '../text';
@@ -174,6 +174,7 @@ const MIN_WIDTH = {
174174
LARGE: 90
175175
};
176176
const DEFAULT_SIZE = ButtonSize.large;
177+
const DISABLED_COLOR = Colors.dark60;
177178

178179
type Props = ButtonPropTypes & BaseComponentInjectedProps & ForwardRefInjectedProps;
179180

@@ -231,6 +232,7 @@ class Button extends PureComponent<Props, ButtonState> {
231232
// This method will be called more than once in case of layout change!
232233
onLayout = (event: LayoutChangeEvent) => {
233234
const height = event.nativeEvent.layout.height;
235+
234236
if (this.props.round) {
235237
const width = event.nativeEvent.layout.width;
236238
const size = height >= width ? height : width;
@@ -264,7 +266,7 @@ class Button extends PureComponent<Props, ButtonState> {
264266

265267
if (!outline && !link) {
266268
if (disabled) {
267-
return disabledBackgroundColor || ThemeManager.CTADisabledColor;
269+
return disabledBackgroundColor || DISABLED_COLOR;
268270
}
269271

270272
return propsBackgroundColor || stateBackgroundColor || themeBackgroundColor || Colors.blue30;
@@ -274,6 +276,7 @@ class Button extends PureComponent<Props, ButtonState> {
274276

275277
getActiveBackgroundColor() {
276278
const {getActiveBackgroundColor} = this.props;
279+
277280
if (getActiveBackgroundColor) {
278281
return getActiveBackgroundColor(this.getBackgroundColor(), this.props);
279282
}
@@ -292,7 +295,7 @@ class Button extends PureComponent<Props, ButtonState> {
292295
}
293296

294297
if (disabled && (link || outline)) {
295-
return ThemeManager.CTADisabledColor;
298+
return DISABLED_COLOR;
296299
}
297300

298301
color = propsColor || extractColorValue(this.props) || color;
@@ -397,6 +400,7 @@ class Button extends PureComponent<Props, ButtonState> {
397400

398401
getBorderRadiusStyle() {
399402
const {link, fullWidth, borderRadius: borderRadiusFromProps, modifiers} = this.props;
403+
400404
if (link || fullWidth || borderRadiusFromProps === 0) {
401405
return {borderRadius: 0};
402406
}
@@ -409,6 +413,7 @@ class Button extends PureComponent<Props, ButtonState> {
409413
getShadowStyle() {
410414
const backgroundColor = this.getBackgroundColor();
411415
const {enableShadow} = this.props;
416+
412417
if (enableShadow) {
413418
return [this.styles.shadowStyle, backgroundColor && {shadowColor: backgroundColor}];
414419
}
@@ -420,8 +425,8 @@ class Button extends PureComponent<Props, ButtonState> {
420425
const iconStyle: ImageStyle = {
421426
tintColor: this.getLabelColor()
422427
};
423-
424428
const marginSide = [Button.sizes.large, Button.sizes.medium].includes(size) ? 8 : 4;
429+
425430
if (!this.isIconButton) {
426431
if (iconOnRight) {
427432
iconStyle.marginLeft = marginSide;
@@ -460,6 +465,7 @@ class Button extends PureComponent<Props, ButtonState> {
460465

461466
if (iconSource) {
462467
const iconStyle = this.getIconStyle();
468+
463469
if (typeof iconSource === 'function') {
464470
return iconSource(iconStyle);
465471
} else {

src/components/image/__tests__/index.spec.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@ describe('Image', () => {
1919
expect(uut.getImageSource()).toBe(2);
2020
});
2121

22-
// TODO: currently impossible to test it cause we can't export the Image we use in tests
23-
// with asBaseComponent
24-
// it('should return transformed source prop, according to sourceTransform in ThemeManager', () => {
25-
// ThemeManager.setTheme({
26-
// components: {
27-
// Image: {
28-
// sourceTransformer: jest.fn(() => 3)
29-
// }
30-
// }
31-
// });
32-
// const uut = new Image({source: 1});
33-
// expect(uut.getImageSource()).toBe(3);
34-
// });
35-
3622
it('should return transformed source prop, according to sourceTransform prop and other given props', () => {
3723
const sourceTransformer = jest.fn(({size, source}) => (size === 'small' ? source : 3));
3824
let uut = new Image({source: 1, size: 'small', sourceTransformer});

src/components/loaderScreen/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
33
import {StyleSheet, ActivityIndicator} from 'react-native';
4-
import {Colors, Typography, ThemeManager} from '../../style';
4+
import {Colors, Typography} from '../../style';
55
import {Constants} from '../../helpers';
66
import {BaseComponent} from '../../commons';
77
import View from '../../components/view';
88
import Text from '../../components/text';
99

10+
1011
/**
1112
* @description: Component that shows a full screen with an activity indicator
1213
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreenScreens/LoadingScreen.js
@@ -50,7 +51,7 @@ export default class LoaderScreen extends BaseComponent {
5051
<ActivityIndicator
5152
size={'large'}
5253
animating
53-
color={loaderColor || (Constants.isIOS ? Colors.dark60 : ThemeManager.primaryColor)}
54+
color={loaderColor || (Constants.isIOS ? Colors.dark60 : Colors.primary)}
5455
{...others}
5556
/>
5657
{!overlay && message && <Text style={[styles.message, messageStyle]}>{message}</Text>}

0 commit comments

Comments
 (0)