Skip to content

Commit 3281d5d

Browse files
committed
Merge branch 'master' into release
2 parents b2e4f73 + 332875d commit 3281d5d

File tree

43 files changed

+750
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+750
-309
lines changed

demo/src/screens/MainScreen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class MainScreen extends Component {
117117
this?.sectionListRef?.current?.scrollToLocation({
118118
animated: true,
119119
sectionIndex: index,
120-
itemIndex: 0,
120+
itemIndex: 1,
121121
viewPosition: 0
122122
});
123123
};

demo/src/screens/componentScreens/CheckboxScreen.tsx

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {Component} from 'react';
22
import {StyleSheet} from 'react-native';
3-
import {Assets, Colors, View, Text, Checkbox} from 'react-native-ui-lib'; //eslint-disable-line
3+
import {Assets, Colors, View, Text, Button, Checkbox, CheckboxRef} from 'react-native-ui-lib'; //eslint-disable-line
44

55
export default class CheckboxScreen extends Component {
66
state = {
@@ -10,7 +10,28 @@ export default class CheckboxScreen extends Component {
1010
value4: true,
1111
value5: false,
1212
value6: false,
13-
value7: true
13+
value7: false,
14+
validationText: '',
15+
validationColor: Colors.$textDefault
16+
};
17+
18+
checkbox = React.createRef<CheckboxRef>();
19+
20+
onPress = () => {
21+
this.checkbox.current?.validate();
22+
};
23+
24+
onValueChange = (value: boolean) => {
25+
this.setState({value7: value}, () => {
26+
console.log('onValueChange: ', value);
27+
});
28+
};
29+
30+
onChangeValidity = (value?: boolean) => {
31+
this.setState({
32+
validationText: String(value),
33+
validationColor: value === true ? Colors.$textSuccess : Colors.$textDangerLight
34+
});
1435
};
1536

1637
render() {
@@ -77,6 +98,24 @@ export default class CheckboxScreen extends Component {
7798
iconColor={Colors.green10}
7899
/>
79100
</View>
101+
102+
<View marginT-20>
103+
<Text text60 $textDefault marginB-10>
104+
Validation
105+
</Text>
106+
<Text marginB-4 color={this.state.validationColor}>{this.state.validationText}</Text>
107+
<View row centerV spread marginB-10>
108+
<Checkbox
109+
required
110+
onChangeValidity={this.onChangeValidity}
111+
ref={this.checkbox}
112+
value={this.state.value7}
113+
onValueChange={this.onValueChange}
114+
label={'This is a checkbox'}
115+
/>
116+
<Button size={'small'} label={'Validate'} onPress={this.onPress}/>
117+
</View>
118+
</View>
80119
</View>
81120
);
82121
}

demo/src/screens/componentScreens/ExpandableSectionScreen.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ExpandableSectionScreen extends PureComponent {
6464
return (
6565
<View margin-10 spread row>
6666
<Text grey10 text60>
67-
ExpandableSection's sectionHeader
67+
ExpandableSection sectionHeader
6868
</Text>
6969
<Image style={styles.icon} source={this.getChevron()}/>
7070
</View>
@@ -73,7 +73,7 @@ class ExpandableSectionScreen extends PureComponent {
7373

7474
getBodyElement() {
7575
return (
76-
<Carousel pageWidth={350} itemSpacings={Spacings.s2}>
76+
<Carousel>
7777
{_.map(this.elements, (element, key) => {
7878
return (
7979
<View key={key} margin-12>

ios/rnuilib/Info.plist

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@
4747
</array>
4848
<key>UISupportedInterfaceOrientations</key>
4949
<array>
50-
<string>UIInterfaceOrientationPortrait</string>
5150
<string>UIInterfaceOrientationLandscapeLeft</string>
5251
<string>UIInterfaceOrientationLandscapeRight</string>
52+
<string>UIInterfaceOrientationPortrait</string>
53+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
5354
</array>
5455
<key>UIViewControllerBasedStatusBarAppearance</key>
55-
<false/>
56+
<true/>
5657
</dict>
5758
</plist>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import PermissionsAcquirer from './NoPermissionsAcquirer';
2+
export default PermissionsAcquirer;

lib/components/DynamicFonts/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import {Platform} from 'react-native';
21
import FontLoader, {FontExtension, LoadFontInput} from './FontLoader';
32
import FontDownloader, {FontDownloaderProps} from './FontDownloader';
4-
import PermissionsAcquirerAndroid, {PermissionsAcquirerProps} from './PermissionsAcquirer.android';
5-
import PermissionsAcquirerIOS from './PermissionsAcquirer.ios';
3+
import type {PermissionsAcquirerProps} from './PermissionsAcquirer.android';
4+
// @ts-expect-error
5+
import PermissionsAcquirer from './PermissionsAcquirer';
66
import NoPermissionsAcquirer from './NoPermissionsAcquirer';
7-
const PermissionsAcquirer = Platform.OS === 'android' ? PermissionsAcquirerAndroid : PermissionsAcquirerIOS;
87

98
const DEFAULT_FONT_LOAD_ERROR_MESSAGE = 'Unable to load this font.';
109

src/commons/Constants.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ let windowWidth: number = Dimensions.get('window').width;
3333
let breakpoints: Breakpoint[];
3434
let defaultMargin = 0;
3535

36+
const isSubWindow = windowWidth < screenWidth;
3637
//@ts-ignore
3738
isTablet = Platform.isPad || (getAspectRatio() < 1.6 && Math.max(screenWidth, screenHeight) >= 900);
3839

@@ -114,12 +115,18 @@ const constants = {
114115
get windowHeight() {
115116
return windowHeight;
116117
},
118+
get isSmallWindow() {
119+
return windowWidth <= 340;
120+
},
117121
get isSmallScreen() {
118122
return screenWidth <= 340;
119123
},
120124
get isShortScreen() {
121125
return screenHeight <= 600;
122126
},
127+
get isWideScreen() {
128+
return isTablet && !isSubWindow || this.isLandscape;
129+
},
123130
get screenAspectRatio() {
124131
return getAspectRatio();
125132
},
@@ -141,16 +148,13 @@ const constants = {
141148
}
142149

143150
for (let i = breakpoints.length - 1; i >= 0; --i) {
144-
if (screenWidth > breakpoints[i].breakpoint) {
151+
if (windowWidth > breakpoints[i].breakpoint) {
145152
return breakpoints[i].pageMargin;
146153
}
147154
}
148155

149156
return defaultMargin;
150157
},
151-
get isWideScreen() {
152-
return isTablet || this.isLandscape;
153-
},
154158
getSafeAreaInsets: () => {
155159
const orientation = getOrientation(screenHeight, screenWidth);
156160
return orientation === orientations.LANDSCAPE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {CarouselProps} from './types';
2+
import {useComponentDriver, ComponentProps} from '../../testkit/new/Component.driver';
3+
import {useScrollableDriver, ScrollProps} from '../../testkit/new/useScrollable.driver';
4+
5+
export const CarouselDriver = (props: ComponentProps) => {
6+
const driver = useScrollableDriver<CarouselProps>(useComponentDriver(props));
7+
8+
const scroll = (props: ScrollProps) => {
9+
return driver.scroll(props);
10+
};
11+
12+
return {...driver, scroll};
13+
};

src/components/carousel/__tests__/index.spec.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,18 @@ import {map} from 'lodash';
22
import React from 'react';
33
import {Text, View} from 'react-native';
44
import {fireOnMomentumScrollEnd} from '../../../uilib-test-renderer';
5+
import {render} from '@testing-library/react-native';
56
import Carousel from '../index';
67
import {Constants} from '../../../commons/new';
7-
import {CarouselDriver} from '../Carousel.driver';
8+
import {CarouselDriver} from '../Carousel.driver.new';
89

910
const numberOfPagesShown = 5;
1011
const onChangePageMock = jest.fn();
1112
const onScrollMock = jest.fn();
1213
const testID = 'carousel';
1314
const TestCase = (props: any) => {
1415
return (
15-
<Carousel
16-
testID={testID}
17-
onChangePage={onChangePageMock}
18-
onScroll={onScrollMock}
19-
{...props}
20-
>
16+
<Carousel testID={testID} onChangePage={onChangePageMock} onScroll={onScrollMock} {...props}>
2117
{map([...Array(numberOfPagesShown)], (_, index) => (
2218
<Page key={index}>
2319
<Text testID={`page-${index}`}>Page #{index}</Text>
@@ -27,7 +23,7 @@ const TestCase = (props: any) => {
2723
);
2824
};
2925

30-
const Page = ({children, ...others}:{children: React.ReactNode, others?: any}) => {
26+
const Page = ({children, ...others}: {children: React.ReactNode; others?: any}) => {
3127
return (
3228
<View {...others} style={{flex: 1}}>
3329
{children}
@@ -36,41 +32,43 @@ const Page = ({children, ...others}:{children: React.ReactNode, others?: any}) =
3632
};
3733

3834
describe('Carousel render tests', () => {
39-
afterEach(() => CarouselDriver.clear());
40-
4135
describe('initialPage', () => {
4236
it('should be set to default initialPage', async () => {
43-
const driver = new CarouselDriver({component: <TestCase/>, testID});
37+
const renderTree = render(<TestCase/>);
38+
const driver = CarouselDriver({renderTree, testID});
4439

4540
expect((await driver.getContentOffset()).x).toBe(0);
4641
});
4742

4843
it('should be set to initialPage = 2', async () => {
49-
const driver = new CarouselDriver({component: <TestCase initialPage={2}/>, testID});
44+
const renderTree = render(<TestCase initialPage={2}/>);
45+
const driver = CarouselDriver({renderTree, testID});
5046

5147
expect((await driver.getContentOffset()).x).toBe(Constants.screenWidth * 2);
5248
});
5349
});
5450

5551
describe('onScroll', () => {
5652
it('should trigger onScroll from the second scroll', async () => {
57-
const driver = new CarouselDriver({component: <TestCase/>, testID});
53+
const renderTree = render(<TestCase/>);
54+
const driver = CarouselDriver({renderTree, testID});
5855

59-
await driver.scroll(Constants.screenWidth); //NOTE: first scroll doesn't fire onScroll
56+
await driver.scroll({x: Constants.screenWidth}); //NOTE: first scroll doesn't fire onScroll
6057
expect(onScrollMock).not.toHaveBeenCalled();
6158

62-
await driver.scroll(Constants.screenWidth);
59+
await driver.scroll({x: Constants.screenWidth});
6360
expect(onScrollMock).toHaveBeenCalled();
6461
});
6562
});
6663

6764
describe('onChangePage', () => {
6865
it('should trigger onChangePage with current page', async () => {
69-
const driver = new CarouselDriver({component: <TestCase/>, testID});
66+
const renderTree = render(<TestCase/>);
67+
const driver = CarouselDriver({renderTree, testID});
7068
const scrollView = await driver.getElement();
7169

72-
await driver.scroll(Constants.screenWidth); //NOTE: first scroll doesn't fire onScroll
73-
await driver.scroll(Constants.screenWidth);
70+
await driver.scroll({x: Constants.screenWidth}); //NOTE: first scroll doesn't fire onScroll
71+
await driver.scroll({x: Constants.screenWidth});
7472
expect(onChangePageMock).not.toHaveBeenCalled();
7573

7674
fireOnMomentumScrollEnd(scrollView, {x: Constants.screenWidth});

0 commit comments

Comments
 (0)