Skip to content

Enable useNative when passing activeScale and add its type #1997

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 2 commits into from
Apr 19, 2022
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
5 changes: 2 additions & 3 deletions demo/src/screens/componentScreens/CardsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export default class CardsScreen extends Component<CardsScreenProps, CardsScreen
style={{marginBottom: 15}}
onPress={() => {}}
borderRadius={borderRadius}
useNative
bg-$backgroundElevated
activeOpacity={1}
activeScale={isImageOnLeft ? 0.96 : 1.04}
Expand Down Expand Up @@ -136,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={() => {}} activeOpacity={1} activeScale={0.96}>
<Card.Section
bg-$backgroundDangerHeavy
padding-20
Expand Down Expand Up @@ -169,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={() => {}} activeOpacity={1} activeScale={0.96}>
{image}
<Card.Section
bg-$backgroundElevated
Expand Down
8 changes: 6 additions & 2 deletions src/components/touchableOpacity/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export interface TouchableOpacityProps extends Omit<RNTouchableOpacityProps, 'st
* Apply background color on TouchableOpacity when active (press is on)
*/
activeBackgroundColor?: string;
/**
* Will apply scale press feedback. This will enforce the useNative prop
*/
activeScale?: number;
/**
* Should use a more native touchable opacity component
*/
Expand Down Expand Up @@ -112,10 +116,10 @@ class TouchableOpacity extends PureComponent<Props, {active: boolean}> {
}

render() {
const {useNative, style, modifiers, forwardedRef, ...others} = this.props;
const {useNative, activeScale, style, modifiers, forwardedRef, ...others} = this.props;
const {borderRadius, paddings, margins, alignments, flexStyle} = modifiers;

if (useNative) {
if (useNative || !_.isUndefined(activeScale)) {
// @ts-ignore
return <IncubatorTouchableOpacity {...this.props}/>;
}
Expand Down