-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Feat/skeleton loading #6814
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
base: develop
Are you sure you want to change the base?
Feat/skeleton loading #6814
Changes from all commits
6128b2b
29d5c00
ccfe315
dec868c
003ae89
f7d04b0
c190e40
3e95327
1c5bf46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| import React from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { Text, useWindowDimensions } from 'react-native'; | ||||||||||||||||||||||||||||||||||||||||||||||
| import type { StyleProp, TextStyle, ImageStyle } from 'react-native'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import { useTheme } from '../../theme'; | ||||||||||||||||||||||||||||||||||||||||||||||
| import useShortnameToUnicode from '../../lib/hooks/useShortnameToUnicode'; | ||||||||||||||||||||||||||||||||||||||||||||||
| import CustomEmoji from '../EmojiPicker/CustomEmoji'; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { useResponsiveLayout } from '../../lib/hooks/useResponsiveLayout/useResponsiveLayout'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| interface ISharedEmojiProps { | ||||||||||||||||||||||||||||||||||||||||||||||
| literal?: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| isBigEmoji?: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||
| style?: StyleProp<TextStyle>; | ||||||||||||||||||||||||||||||||||||||||||||||
| isAvatar?: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||
| getCustomEmoji?: (name: string) => any; | ||||||||||||||||||||||||||||||||||||||||||||||
| customEmoji?: any; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const Emoji = ({ literal, isBigEmoji, style, isAvatar, getCustomEmoji, customEmoji }: ISharedEmojiProps) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const { colors } = useTheme(); | ||||||||||||||||||||||||||||||||||||||||||||||
| const { formatShortnameToUnicode } = useShortnameToUnicode(); | ||||||||||||||||||||||||||||||||||||||||||||||
| const { fontScale } = useWindowDimensions(); | ||||||||||||||||||||||||||||||||||||||||||||||
| const { fontScaleLimited } = useResponsiveLayout(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Calculate emoji sizes once to avoid duplication | ||||||||||||||||||||||||||||||||||||||||||||||
| const customEmojiSize = { | ||||||||||||||||||||||||||||||||||||||||||||||
| width: 15 * fontScale, | ||||||||||||||||||||||||||||||||||||||||||||||
| height: 15 * fontScale | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
| const customEmojiBigSize = { | ||||||||||||||||||||||||||||||||||||||||||||||
| width: 30 * fontScale, | ||||||||||||||||||||||||||||||||||||||||||||||
| height: 30 * fontScale | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (customEmoji) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return <CustomEmoji style={[isBigEmoji ? customEmojiBigSize : customEmojiSize, style as StyleProp<ImageStyle>]} emoji={customEmoji} />; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (!literal) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const emojiUnicode = formatShortnameToUnicode(literal); | ||||||||||||||||||||||||||||||||||||||||||||||
| const emojiName = literal.replace(/:/g, ''); | ||||||||||||||||||||||||||||||||||||||||||||||
| const foundCustomEmoji = getCustomEmoji?.(emojiName); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (foundCustomEmoji) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return <CustomEmoji style={[isBigEmoji ? customEmojiBigSize : customEmojiSize, style as StyleProp<ImageStyle>]} emoji={foundCustomEmoji} />; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const avatarStyle = { | ||||||||||||||||||||||||||||||||||||||||||||||
| fontSize: 30 * fontScaleLimited, | ||||||||||||||||||||||||||||||||||||||||||||||
| lineHeight: 30 * fontScaleLimited, | ||||||||||||||||||||||||||||||||||||||||||||||
| textAlign: 'center' as const | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||
| <Text | ||||||||||||||||||||||||||||||||||||||||||||||
| style={[ | ||||||||||||||||||||||||||||||||||||||||||||||
| { color: colors.fontDefault }, | ||||||||||||||||||||||||||||||||||||||||||||||
| isBigEmoji ? { fontSize: 30, lineHeight: 43 } : { fontSize: 16, lineHeight: 22 }, | ||||||||||||||||||||||||||||||||||||||||||||||
| style, | ||||||||||||||||||||||||||||||||||||||||||||||
| isAvatar && avatarStyle | ||||||||||||||||||||||||||||||||||||||||||||||
| ]}> | ||||||||||||||||||||||||||||||||||||||||||||||
| {emojiUnicode} | ||||||||||||||||||||||||||||||||||||||||||||||
| </Text> | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+58
to
+68
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider accessibility: hard-coded font sizes don't respect user preferences. Line 62 uses fixed Consider applying consistent scaling: return (
<Text
style={[
{ color: colors.fontDefault },
- isBigEmoji ? { fontSize: 30, lineHeight: 43 } : { fontSize: 16, lineHeight: 22 },
+ isBigEmoji ? { fontSize: 30 * fontScaleLimited, lineHeight: 43 * fontScaleLimited } : { fontSize: 16 * fontScaleLimited, lineHeight: 22 * fontScaleLimited },
style,
isAvatar && avatarStyle
]}>
{emojiUnicode}
</Text>
);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| export default Emoji; | ||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react-native'; | ||
|
|
||
| import Emoji from '../Emoji'; | ||
|
|
||
| // Mock dependencies | ||
| jest.mock('../../../lib/hooks/useShortnameToUnicode', () => ({ | ||
| __esModule: true, | ||
| default: () => ({ | ||
| formatShortnameToUnicode: (str: string) => (str === ':smile:' ? '😄' : str) | ||
| }) | ||
| })); | ||
|
|
||
| jest.mock('../../EmojiPicker/CustomEmoji', () => { | ||
| const { View } = require('react-native'); | ||
| return (props: any) => <View testID="mock-custom-emoji" {...props} />; | ||
| }); | ||
|
|
||
| jest.mock('../../../theme', () => ({ | ||
| useTheme: () => ({ colors: { fontDefault: 'black' } }) | ||
| })); | ||
|
|
||
| jest.mock('../../../lib/hooks/useResponsiveLayout/useResponsiveLayout', () => ({ | ||
| useResponsiveLayout: () => ({ fontScaleLimited: 1 }) | ||
| })); | ||
|
|
||
| describe('Emoji', () => { | ||
| it('renders standard emoji correctly', () => { | ||
| const { getByText } = render(<Emoji literal=":smile:" />); | ||
| expect(getByText('😄')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('renders custom emoji correctly', () => { | ||
| const customEmoji = { name: 'party_parrot', extension: 'gif' }; | ||
| const { getByTestId } = render(<Emoji customEmoji={customEmoji} />); | ||
| expect(getByTestId('mock-custom-emoji')).toBeTruthy(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default as Emoji } from './Emoji'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,12 @@ | ||
| import React from 'react'; | ||
| import { Text } from 'react-native'; | ||
|
|
||
| import useShortnameToUnicode from '../../lib/hooks/useShortnameToUnicode'; | ||
| import styles from './styles'; | ||
| import CustomEmoji from './CustomEmoji'; | ||
| import { type IEmojiProps } from './interfaces'; | ||
| import SharedEmoji from '../Emoji/Emoji'; | ||
|
|
||
| export const Emoji = ({ emoji }: IEmojiProps): React.ReactElement => { | ||
| const { formatShortnameToUnicode } = useShortnameToUnicode(true); | ||
| const unicodeEmoji = formatShortnameToUnicode(`:${emoji}:`); | ||
|
|
||
| if (typeof emoji === 'string') { | ||
| return <Text style={styles.categoryEmoji}>{unicodeEmoji}</Text>; | ||
| return <SharedEmoji literal={`:${emoji}:`} style={styles.categoryEmoji} />; | ||
| } | ||
| return <CustomEmoji style={styles.customCategoryEmoji} emoji={emoji} />; | ||
| return <SharedEmoji customEmoji={emoji} style={styles.customCategoryEmoji} />; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import React from 'react'; | ||
| import SkeletonPlaceholder from 'react-native-skeleton-placeholder'; | ||
| import { type DimensionValue, type StyleProp, type ViewStyle } from 'react-native'; | ||
|
|
||
| import { useTheme } from '../../theme'; | ||
|
|
||
| interface ISkeletonProps { | ||
| width?: DimensionValue; | ||
| height?: DimensionValue; | ||
| borderRadius?: number; | ||
| style?: StyleProp<ViewStyle>; | ||
| } | ||
|
|
||
| const Skeleton = ({ width, height, borderRadius, style }: ISkeletonProps): React.ReactElement => { | ||
| const { colors } = useTheme(); | ||
|
|
||
| return ( | ||
| <SkeletonPlaceholder backgroundColor={colors.surfaceTint}> | ||
| <SkeletonPlaceholder.Item width={width} height={height} borderRadius={borderRadius} style={style} /> | ||
| </SkeletonPlaceholder> | ||
| ); | ||
| }; | ||
|
|
||
| export default Skeleton; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react-native'; | ||
|
|
||
| import Skeleton from '../index'; | ||
|
|
||
| // Mock useTheme | ||
| jest.mock('../../theme', () => ({ | ||
| useTheme: () => ({ colors: { surfaceTint: 'gray', surfaceHover: 'lightgray' } }) | ||
| })); | ||
|
|
||
| jest.mock('react-native-skeleton-placeholder', () => { | ||
| const { View } = require('react-native'); | ||
| const MockSkeleton = ({ children }: any) => <View testID="skeleton-placeholder">{children}</View>; | ||
| MockSkeleton.Item = ({ children }: any) => <View testID="skeleton-item">{children}</View>; | ||
| return MockSkeleton; | ||
| }); | ||
|
|
||
| describe('Skeleton', () => { | ||
| it('renders correctly', () => { | ||
| const { toJSON } = render(<Skeleton width={100} height={100} />); | ||
| expect(toJSON()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('applies styles correctly', () => { | ||
| const { toJSON } = render(<Skeleton width={50} height={50} borderRadius={10} />); | ||
| expect(toJSON()).toMatchSnapshot(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './Skeleton'; |
Uh oh!
There was an error while loading. Please reload this page.