Skip to content

Commit

Permalink
Merge pull request #775 from thundersdata-frontend/feat/noticebar
Browse files Browse the repository at this point in the history
feat(custom): noticebar支持修改文本颜色
  • Loading branch information
chj-damon authored Nov 29, 2023
2 parents 78f8169 + cc5dadb commit 2fe1910
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-fans-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@td-design/react-native': patch
---

noticeBar支持修改文本颜色
10 changes: 8 additions & 2 deletions packages/react-native/src/notice-bar/AnimatedNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const { deviceWidth } = helpers;
const AnimatedNotice: FC<AnimatedNoticeProps & { height: number; onContentLayout: (e: LayoutChangeEvent) => void }> = ({
icon,
text,
textColor,
animated,
height,
onContentLayout,
Expand Down Expand Up @@ -79,13 +80,18 @@ const AnimatedNotice: FC<AnimatedNoticeProps & { height: number; onContentLayout
</Box>
<Flex width={deviceWidth * 10} onLayout={onContentLayout}>
<Animated.View style={animatedStyle}>
<Text variant={'p1'} color="text" numberOfLines={1} onLayout={e => setTextWidth(e.nativeEvent.layout.width)}>
<Text
variant={'p1'}
color={textColor}
numberOfLines={1}
onLayout={e => setTextWidth(e.nativeEvent.layout.width)}
>
{textWithTail}
</Text>
</Animated.View>
{animated && (
<Animated.View style={animatedStyle}>
<Text variant={'p1'} color="text" numberOfLines={1}>
<Text variant={'p1'} color={textColor} numberOfLines={1}>
{textWithTail}
</Text>
</Animated.View>
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/src/notice-bar/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ group:
| 属性 | 必填 | 说明 | 类型 | 默认值 |
| ------------- | ------- | ---------------- | ------------------------- | ------- |
| text | `true` | 通告栏文本 | `string` | |
| textColor | `false` | 通告栏文本颜色 | `keyof Theme['colors']` | |
| icon | `false` | 左侧图标 | `ReactNode` | |
| mode | `false` | 通告栏类型 | `close` \| `link` \| `''` | `''` |
| onPress | `false` | 通告栏点击事件 | `() => void` | |
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native/src/notice-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const NoticeBar: FC<NoticeBarProps> = props => {
icon = <SvgIcon name="bells" color={theme.colors.func500} />,
mode = '',
text = '',
textColor = 'text',
onPress,
duration = DEFAULT_DURATION,
animated = false,
Expand All @@ -38,7 +39,7 @@ const NoticeBar: FC<NoticeBarProps> = props => {
if (!visible) return null;

const BaseContent = (
<AnimatedNotice {...{ text, icon, duration, animated, height, onContentLayout: handleContentLayout }} />
<AnimatedNotice {...{ text, textColor, icon, duration, animated, height, onContentLayout: handleContentLayout }} />
);

switch (mode) {
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/src/notice-bar/type.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { ReactNode } from 'react';
import { StyleProp, ViewStyle } from 'react-native';

import { Theme } from 'src/theme';

export interface NoticeBarProps {
/** 左侧自定义图标 */
icon?: ReactNode;
/** 通知栏内容 */
text: string;
/** 文字颜色 */
textColor?: keyof Theme['colors'];
/** 通知栏模式。close表示可关闭;link表示可点击;默认为空 */
mode?: 'close' | 'link' | '';
/** 点击事件 */
Expand Down

0 comments on commit 2fe1910

Please sign in to comment.