Skip to content

Card - fix missing types when sending useNative (send nativeProps instead) #1631

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

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 3 additions & 5 deletions demo/src/screens/componentScreens/CardsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ export default class CardsScreen extends Component<CardsScreenProps, CardsScreen
style={{marginBottom: 15}}
onPress={() => {}}
borderRadius={borderRadius}
useNative
backgroundColor={Colors.white}
activeOpacity={1}
activeScale={isImageOnLeft ? 0.96 : 1.04}
nativeProps={{activeOpacity: 1, activeScale: isImageOnLeft ? 0.96 : 1.04}}
>
{isImageOnLeft && (
<Card.Section
Expand Down Expand Up @@ -137,7 +135,7 @@ export default class CardsScreen extends Component<CardsScreenProps, CardsScreen

renderCoupon = (cardProps: CardProps) => {
return (
<Card {...cardProps} flex height={160} onPress={() => {}} useNative activeOpacity={1} activeScale={0.96}>
<Card {...cardProps} flex height={160} onPress={() => {}} nativeProps={{activeOpacity: 1, activeScale: 0.96}}>
<Card.Section
bg-red30
padding-20
Expand Down Expand Up @@ -170,7 +168,7 @@ export default class CardsScreen extends Component<CardsScreenProps, CardsScreen

renderComplexImage = (cardProps: CardProps, image: React.ReactNode) => {
return (
<Card {...cardProps} flex marginV-10 onPress={() => {}} useNative activeOpacity={1} activeScale={0.96}>
<Card {...cardProps} flex marginV-10 onPress={() => {}} nativeProps={{activeOpacity: 1, activeScale: 0.96}}>
{image}
<Card.Section
bg-white
Expand Down
25 changes: 23 additions & 2 deletions generatedTypes/src/components/card/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { ViewStyle } from 'react-native';
import { ViewProps } from '../view';
import { TouchableOpacityProps as NativeTouchableOpacityProps } from '../../incubator/TouchableOpacity';
import { TouchableOpacityProps } from '../touchableOpacity';
import CardImage from './CardImage';
import CardSection, { CardSectionProps } from './CardSection';
Expand All @@ -13,7 +14,7 @@ export interface CardSelectionOptions {
hideIndicator?: boolean;
}
export { CardSectionProps };
export declare type CardProps = ViewProps & TouchableOpacityProps & {
export declare type CardProps = ViewProps & Omit<TouchableOpacityProps, 'useNative'> & {
/**
* card custom width
*/
Expand Down Expand Up @@ -62,8 +63,18 @@ export declare type CardProps = ViewProps & TouchableOpacityProps & {
* Custom options for styling the selection indication
*/
selectionOptions?: CardSelectionOptions;
/**
* '@deprecated
* - Please start using nativeProps instead
* - Should use a more native touchable opacity component
*/
useNative?: boolean;
/**
* Should use a more native touchable opacity component.
*/
nativeProps?: Omit<Exclude<NativeTouchableOpacityProps, TouchableOpacityProps>, 'style'>;
};
declare const _default: React.ComponentClass<ViewProps & TouchableOpacityProps & {
declare const _default: React.ComponentClass<ViewProps & Omit<TouchableOpacityProps, "useNative"> & {
/**
* card custom width
*/
Expand Down Expand Up @@ -112,6 +123,16 @@ declare const _default: React.ComponentClass<ViewProps & TouchableOpacityProps &
* Custom options for styling the selection indication
*/
selectionOptions?: CardSelectionOptions | undefined;
/**
* '@deprecated
* - Please start using nativeProps instead
* - Should use a more native touchable opacity component
*/
useNative?: boolean | undefined;
/**
* Should use a more native touchable opacity component.
*/
nativeProps?: Omit<NativeTouchableOpacityProps, "style"> | undefined;
} & {
useCustomTheme?: boolean | undefined;
}, any> & {
Expand Down
18 changes: 16 additions & 2 deletions src/components/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Colors, BorderRadiuses} from '../../style';
// import {PureBaseComponent} from '../../commons';
import {asBaseComponent, forwardRef, BaseComponentInjectedProps, ForwardRefInjectedProps} from '../../commons/new';
import View, {ViewProps} from '../view';
import {TouchableOpacityProps as NativeTouchableOpacityProps} from '../../incubator/TouchableOpacity';
import TouchableOpacity, {TouchableOpacityProps} from '../touchableOpacity';
import Image from '../image';
import CardImage from './CardImage';
Expand Down Expand Up @@ -39,7 +40,7 @@ export interface CardSelectionOptions {

export {CardSectionProps};
export type CardProps = ViewProps &
TouchableOpacityProps & {
Omit<TouchableOpacityProps, 'useNative'> & {
/**
* card custom width
*/
Expand Down Expand Up @@ -88,6 +89,16 @@ export type CardProps = ViewProps &
* Custom options for styling the selection indication
*/
selectionOptions?: CardSelectionOptions;
/**
* '@deprecated
* - Please start using nativeProps instead
* - Should use a more native touchable opacity component
*/
useNative?: boolean;
/**
* Should use a more native touchable opacity component.
*/
nativeProps?: Omit<Exclude<NativeTouchableOpacityProps, TouchableOpacityProps>, 'style'>;
};

type PropTypes = BaseComponentInjectedProps & ForwardRefInjectedProps & CardProps;
Expand Down Expand Up @@ -257,7 +268,8 @@ class Card extends PureComponent<PropTypes, State> {
};

render() {
const {onPress, onLongPress, style, selected, containerStyle, enableBlur, forwardedRef, ...others} = this.props;
const {onPress, onLongPress, style, selected, containerStyle, enableBlur, forwardedRef, nativeProps, ...others} =
this.props;
const blurOptions = this.getBlurOptions();
const Container = onPress || onLongPress ? TouchableOpacity : View;
const brRadius = this.borderRadius;
Expand All @@ -279,6 +291,8 @@ class Card extends PureComponent<PropTypes, State> {
activeOpacity={0.6}
accessibilityState={{selected}}
{...others}
{...nativeProps}
useNative={!_.isEmpty(nativeProps)}
ref={forwardedRef}
>
{Constants.isIOS && enableBlur && BlurView && (
Expand Down