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 all commits
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
1 change: 1 addition & 0 deletions generatedTypes/components/modal/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface ModalProps extends RNModalProps {
declare class Modal extends Component<ModalProps> {
static displayName: string;
static TopBar: typeof TopBar;
constructor(props: ModalProps);
renderTouchableOverlay(): JSX.Element | undefined;
render(): JSX.Element;
}
Expand Down
12 changes: 10 additions & 2 deletions src/components/card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _ from 'lodash';
import React, {PureComponent} from 'react';
import {StyleSheet, Animated, ViewStyle} from 'react-native';
import {BlurView} from '@react-native-community/blur';
import {Constants} from '../../helpers';
import {Colors, BorderRadiuses} from '../../style';
// import {PureBaseComponent} from '../../commons';
Expand All @@ -21,6 +20,11 @@ import Assets from '../../assets';
import CardContext from './CardContext';
import * as CardPresenter from './CardPresenter';

let BlurView: any;
try {
BlurView = require('@react-native-community/blur').BlurView;
} catch (error) {} // warning in ctor, depends if user pass enableBlur

const DEFAULT_BORDER_RADIUS = BorderRadiuses.br40;
const DEFAULT_SELECTION_PROPS = {
borderWidth: 2,
Expand Down Expand Up @@ -125,6 +129,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 +311,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
16 changes: 14 additions & 2 deletions src/components/modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import _ from 'lodash';
import React, {Component} from 'react';
import {StyleSheet, Modal as RNModal, ModalProps as RNModalProps, TouchableWithoutFeedback, GestureResponderEvent} from 'react-native';
import {BlurView} from '@react-native-community/blur';
import {Constants} from '../../helpers';
import {asBaseComponent} from '../../commons/new';
import TopBar, {ModalTopBarProps} from './TopBar';
import View from '../../components/view';

let BlurView: any;
try {
BlurView = require('@react-native-community/blur').BlurView;
} catch (error) {} // warning in ctor, depends if user pass enableBlur

export {ModalTopBarProps};
export interface ModalProps extends RNModalProps {
/**
Expand Down Expand Up @@ -47,6 +51,14 @@ class Modal extends Component<ModalProps> {
static displayName = 'Modal';
static TopBar: typeof TopBar;

constructor(props: ModalProps) {
super(props);

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

renderTouchableOverlay() {
const {testID, overlayBackgroundColor, onBackgroundPress, accessibilityLabel = 'Dismiss'} = this.props;
if (_.isFunction(onBackgroundPress) || !!overlayBackgroundColor) {
Expand Down Expand Up @@ -74,7 +86,7 @@ class Modal extends Component<ModalProps> {

render() {
const {blurView, enableModalBlur, visible, ...others} = this.props;
const defaultContainer = enableModalBlur && Constants.isIOS ? BlurView : View;
const defaultContainer = enableModalBlur && Constants.isIOS && BlurView ? BlurView : View;
const Container: any = blurView ? blurView : defaultContainer;

return (
Expand Down
2 changes: 0 additions & 2 deletions typings/components/Toast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import {BaseComponent} from '../commons';
import {ColorValue} from '../style/colors';
import {ButtonProps} from './Button';
import {BlurViewProperties} from '@react-native-community/blur';

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

Expand All @@ -31,7 +30,6 @@ export interface ToastProps {
centerMessage?: boolean;
animated?: boolean;
enableBlur?: boolean;
blurOptions?: BlurViewProperties;
zIndex?: number;
}

Expand Down