Skip to content

Safe require blur-view dependency in Card #1179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions generatedTypes/components/card/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ declare const _default: React.ComponentClass<ViewProps & Pick<import("react-nati
activeBackgroundColor?: string | undefined;
useNative?: boolean | undefined;
customValue?: any;
/**
* card custom height
*/
style?: false | {} | ViewStyle | import("react-native").RegisteredStyle<ViewStyle> | import("react-native").RecursiveArray<false | ViewStyle | import("react-native").RegisteredStyle<ViewStyle> | null | undefined> | {
backfaceVisibility?: "visible" | "hidden" | Animated.Value | Animated.AnimatedInterpolation | undefined;
backgroundColor?: string | typeof import("react-native").OpaqueColorValue | Animated.Value | Animated.AnimatedInterpolation | undefined;
Expand Down
15 changes: 13 additions & 2 deletions src/components/card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import _ from 'lodash';
import React, {PureComponent} from 'react';
import {StyleSheet, Animated, ViewStyle} from 'react-native';
import {BlurView} from '@react-native-community/blur';

let BlurView: any;
try {
BlurView = require('@react-native-community/blur').BlurView;
} catch (error) {
// warning in ctor, depends if user pass enableBlur
}
// import {BlurView} from '@react-native-community/blur';
import {Constants} from '../../helpers';
import {Colors, BorderRadiuses} from '../../style';
// import {PureBaseComponent} from '../../commons';
Expand Down Expand Up @@ -125,6 +132,10 @@ class Card extends PureComponent<PropTypes, State> {
animatedSelected: new Animated.Value(Number(this.props.selected))
};
this.styles = createStyles(this.props);

if (props.enableBlur && !BlurView) {
console.error(`RNUILib Card's "enableBlur" prop requires installing "@react-native-community/blur" dependency`);
}
}

componentDidUpdate(prevProps: PropTypes) {
Expand Down Expand Up @@ -303,7 +314,7 @@ class Card extends PureComponent<PropTypes, State> {
{...others}
ref={forwardedRef}
>
{Constants.isIOS && enableBlur && (
{Constants.isIOS && enableBlur && BlurView && (
// @ts-ignore
<BlurView
style={[this.styles.blurView, {borderRadius: brRadius}]}
Expand Down