Skip to content

Commit af976f0

Browse files
authored
Safe require blur-view dependency in Card (#1179)
* safe require blur-view dependency in card and warn user if missing * Add optional require for blur-view package in Modal component * Update generate types
1 parent e3eb3dd commit af976f0

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

generatedTypes/components/card/index.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ declare const _default: React.ComponentClass<ViewProps & Pick<import("react-nati
7373
activeBackgroundColor?: string | undefined;
7474
useNative?: boolean | undefined;
7575
customValue?: any;
76-
/**
77-
* card custom height
78-
*/
7976
style?: false | {} | ViewStyle | import("react-native").RegisteredStyle<ViewStyle> | import("react-native").RecursiveArray<false | ViewStyle | import("react-native").RegisteredStyle<ViewStyle> | null | undefined> | {
8077
backfaceVisibility?: "visible" | "hidden" | Animated.Value | Animated.AnimatedInterpolation | undefined;
8178
backgroundColor?: string | typeof import("react-native").OpaqueColorValue | Animated.Value | Animated.AnimatedInterpolation | undefined;

generatedTypes/components/modal/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface ModalProps extends RNModalProps {
3939
declare class Modal extends Component<ModalProps> {
4040
static displayName: string;
4141
static TopBar: typeof TopBar;
42+
constructor(props: ModalProps);
4243
renderTouchableOverlay(): JSX.Element | undefined;
4344
render(): JSX.Element;
4445
}

src/components/card/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import _ from 'lodash';
22
import React, {PureComponent} from 'react';
33
import {StyleSheet, Animated, ViewStyle} from 'react-native';
4-
import {BlurView} from '@react-native-community/blur';
54
import {Constants} from '../../helpers';
65
import {Colors, BorderRadiuses} from '../../style';
76
// import {PureBaseComponent} from '../../commons';
@@ -21,6 +20,11 @@ import Assets from '../../assets';
2120
import CardContext from './CardContext';
2221
import * as CardPresenter from './CardPresenter';
2322

23+
let BlurView: any;
24+
try {
25+
BlurView = require('@react-native-community/blur').BlurView;
26+
} catch (error) {} // warning in ctor, depends if user pass enableBlur
27+
2428
const DEFAULT_BORDER_RADIUS = BorderRadiuses.br40;
2529
const DEFAULT_SELECTION_PROPS = {
2630
borderWidth: 2,
@@ -125,6 +129,10 @@ class Card extends PureComponent<PropTypes, State> {
125129
animatedSelected: new Animated.Value(Number(this.props.selected))
126130
};
127131
this.styles = createStyles(this.props);
132+
133+
if (props.enableBlur && !BlurView) {
134+
console.error(`RNUILib Card's "enableBlur" prop requires installing "@react-native-community/blur" dependency`);
135+
}
128136
}
129137

130138
componentDidUpdate(prevProps: PropTypes) {
@@ -303,7 +311,7 @@ class Card extends PureComponent<PropTypes, State> {
303311
{...others}
304312
ref={forwardedRef}
305313
>
306-
{Constants.isIOS && enableBlur && (
314+
{Constants.isIOS && enableBlur && BlurView && (
307315
// @ts-ignore
308316
<BlurView
309317
style={[this.styles.blurView, {borderRadius: brRadius}]}

src/components/modal/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import _ from 'lodash';
22
import React, {Component} from 'react';
33
import {StyleSheet, Modal as RNModal, ModalProps as RNModalProps, TouchableWithoutFeedback, GestureResponderEvent} from 'react-native';
4-
import {BlurView} from '@react-native-community/blur';
54
import {Constants} from '../../helpers';
65
import {asBaseComponent} from '../../commons/new';
76
import TopBar, {ModalTopBarProps} from './TopBar';
87
import View from '../../components/view';
98

9+
let BlurView: any;
10+
try {
11+
BlurView = require('@react-native-community/blur').BlurView;
12+
} catch (error) {} // warning in ctor, depends if user pass enableBlur
13+
1014
export {ModalTopBarProps};
1115
export interface ModalProps extends RNModalProps {
1216
/**
@@ -47,6 +51,14 @@ class Modal extends Component<ModalProps> {
4751
static displayName = 'Modal';
4852
static TopBar: typeof TopBar;
4953

54+
constructor(props: ModalProps) {
55+
super(props);
56+
57+
if (props.enableModalBlur && !BlurView) {
58+
console.error(`RNUILib Modal's "enableModalBlur" prop requires installing "@react-native-community/blur" dependency`);
59+
}
60+
}
61+
5062
renderTouchableOverlay() {
5163
const {testID, overlayBackgroundColor, onBackgroundPress, accessibilityLabel = 'Dismiss'} = this.props;
5264
if (_.isFunction(onBackgroundPress) || !!overlayBackgroundColor) {
@@ -74,7 +86,7 @@ class Modal extends Component<ModalProps> {
7486

7587
render() {
7688
const {blurView, enableModalBlur, visible, ...others} = this.props;
77-
const defaultContainer = enableModalBlur && Constants.isIOS ? BlurView : View;
89+
const defaultContainer = enableModalBlur && Constants.isIOS && BlurView ? BlurView : View;
7890
const Container: any = blurView ? blurView : defaultContainer;
7991

8092
return (

typings/components/Toast.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import {BaseComponent} from '../commons';
1010
import {ColorValue} from '../style/colors';
1111
import {ButtonProps} from './Button';
12-
import {BlurViewProperties} from '@react-native-community/blur';
1312

1413
export type ToastPosition = "relative" | "top" | "bottom";
1514

@@ -31,7 +30,6 @@ export interface ToastProps {
3130
centerMessage?: boolean;
3231
animated?: boolean;
3332
enableBlur?: boolean;
34-
blurOptions?: BlurViewProperties;
3533
zIndex?: number;
3634
}
3735

0 commit comments

Comments
 (0)