Skip to content

Commit

Permalink
Merge pull request #749 from thundersdata-frontend/refactor-rn
Browse files Browse the repository at this point in the history
fix: 修改几个组件里children的类型定义方式
  • Loading branch information
chj-damon authored Oct 17, 2023
2 parents 2062632 + 616feb4 commit cc6d241
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-dolls-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@td-design/react-native': patch
---

修改几个组件里children的类型定义方式
52 changes: 26 additions & 26 deletions packages/react-native/src/card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, memo, PropsWithChildren, ReactNode } from 'react';
import React, { FC, memo, ReactNode } from 'react';
import { StyleProp, StyleSheet, ViewStyle } from 'react-native';

import { useTheme } from '@shopify/restyle';
Expand Down Expand Up @@ -27,14 +27,16 @@ export interface CardProps {
containerStyle?: StyleProp<ViewStyle>;
/** 容器内content样式 */
contentStyle?: StyleProp<ViewStyle>;
/** 子组件 */
children?: ReactNode;
}

/**
* Card 组件由Header(可选)/Content/Footer(可选)三部分组成
* @param param0
* @returns
*/
const Card: FC<PropsWithChildren<CardProps>> = ({
const Card: FC<CardProps> = ({
icon,
title,
extra,
Expand Down Expand Up @@ -119,28 +121,26 @@ const Header = memo(
}
);

const Body = memo(
({ footer, contentStyle, children }: Pick<PropsWithChildren<CardProps>, 'footer' | 'contentStyle' | 'children'>) => {
const theme = useTheme<Theme>();
const Body = memo(({ footer, contentStyle, children }: Pick<CardProps, 'footer' | 'contentStyle' | 'children'>) => {
const theme = useTheme<Theme>();

return (
<Box
padding="x2"
style={
footer
? StyleSheet.compose(
{
borderBottomWidth: ONE_PIXEL,
borderBottomColor: theme.colors.border,
paddingBottom: theme.spacing.x2,
},
contentStyle
)
: contentStyle
}
>
{children}
</Box>
);
}
);
return (
<Box
padding="x2"
style={
footer
? StyleSheet.compose(
{
borderBottomWidth: ONE_PIXEL,
borderBottomColor: theme.colors.border,
paddingBottom: theme.spacing.x2,
},
contentStyle
)
: contentStyle
}
>
{children}
</Box>
);
});
6 changes: 3 additions & 3 deletions packages/react-native/src/pressable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* effect is the invocation of `onPress` and `onLongPress` that occur when a
* responder is release while in the "press in" states.
*/
import React, { memo, PropsWithChildren } from 'react';
import React, { memo } from 'react';
import { Pressable as RNPressable, PressableProps as RNPressableProps, StyleProp, ViewStyle } from 'react-native';

import helpers from '../helpers';
Expand All @@ -44,7 +44,7 @@ type Rect = {
export interface PressableProps
extends Pick<
RNPressableProps,
'onPress' | 'onPressIn' | 'onPressOut' | 'onLongPress' | 'disabled' | 'delayLongPress' | 'onLayout'
'onPress' | 'onPressIn' | 'onPressOut' | 'onLongPress' | 'disabled' | 'delayLongPress' | 'onLayout' | 'children'
> {
/** 点击时的不透明度 */
activeOpacity?: number;
Expand All @@ -58,7 +58,7 @@ export interface PressableProps
}

const { px } = helpers;
function Pressable(props: PropsWithChildren<PressableProps>) {
function Pressable(props: PressableProps) {
const {
children,
activeOpacity = 0.6,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/src/swipe-row/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type SwipeRowProps = PropsWithChildren<{
onRemove?: () => Promise<boolean>;
/** 是否覆盖默认操作项 */
overwriteDefaultActions?: boolean;
/** Swiperable自身的样式 */
/** Swipeable自身的样式 */
containerStyle?: StyleProp<ViewStyle>;
/** Swipeable的子组件样式 */
contentContainerStyle?: StyleProp<ViewStyle>;
Expand Down

0 comments on commit cc6d241

Please sign in to comment.