-
Notifications
You must be signed in to change notification settings - Fork 4
Feat(v2): Image component #74
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
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
612d7c9
feat(components/image): add component, add to example, add to doc, adβ¦
Zero6d fc80433
feat(components/image): add Box as Image API
Zero6d d467e0d
chore: change from source uri to src
Zero6d 9c17c1b
Merge branch 'next' into feat/v2-image
ntatoud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| --- | ||
| searchable: true | ||
| --- | ||
|
|
||
| import { CodeEditor } from '@components/code-editor'; | ||
|
|
||
| # Image | ||
|
|
||
| Wrapper around `Image` component from `react-native`, it accepts every props from react native `Image` component. | ||
|
|
||
| ## Import | ||
|
|
||
| ```js | ||
| import { Image } from "@ficus-ui/native"; | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| <CodeEditor code={`<Image | ||
| h={200} | ||
| w={300} | ||
| borderRadius={10} | ||
| source={{ | ||
| uri: | ||
| 'https://www.picturethisai.com/wiki-image/1080/153400456440184865.jpeg', | ||
| }} | ||
| />`} /> | ||
|
|
||
| ## Props | ||
|
|
||
| Extends every `Box` and from react native `Image` component : https://reactnative.dev/docs/image#props | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { Box, Image, SafeAreaBox, Text } from '@ficus-ui/native'; | ||
|
|
||
|
|
||
| const ImageComponent = () => { | ||
| return ( | ||
| <SafeAreaBox style={{ flex: 1 }}> | ||
Zero6d marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Text mx="xl" fontSize="4xl"> | ||
| Image component | ||
| </Text> | ||
| <Box mx="xl" mt="lg"> | ||
| <Image | ||
| h={200} | ||
| w={300} | ||
| borderRadius={10} | ||
| source={{ | ||
| uri: 'https://www.picturethisai.com/wiki-image/1080/153400456440184865.jpeg', | ||
| }} | ||
| /> | ||
| </Box> | ||
| </SafeAreaBox> | ||
| ); | ||
| }; | ||
|
|
||
| export default ImageComponent; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,27 @@ | ||
| import { type NativeFicusProps, ficus } from '../system'; | ||
| import { ImageSourcePropType } from 'react-native'; | ||
|
|
||
| // TODO: Improve Box as Image API from V1 | ||
| export interface BoxProps extends NativeFicusProps<'View'> {} | ||
| import { type NativeFicusProps, ficus, forwardRef } from '../system'; | ||
|
|
||
| export const Box = ficus('View'); | ||
| interface BoxOptions { | ||
| bgImg?: ImageSourcePropType; | ||
| bgMode?: 'contain' | 'cover' | 'stretch' | 'repeat'; | ||
| } | ||
|
|
||
| export const Circle = ficus('View', { | ||
| baseStyle: { | ||
| borderRadius: 'full', | ||
| }, | ||
| export interface BoxProps extends NativeFicusProps<'View'>, BoxOptions {} | ||
|
|
||
| /** | ||
| * Boxs help you easily create flexible and automatically distributed layouts | ||
| * | ||
| * You can Box elements in the horizontal or vertical direction, | ||
| * and apply a space or/and divider between each element. | ||
| * | ||
| */ | ||
| export const Box = forwardRef<BoxProps, 'View'>((props, ref) => { | ||
| const { bgImg, bgMode, ...rest } = props; | ||
| if (bgImg) { | ||
| return ( | ||
| <ficus.Image ref={ref} source={bgImg} resizeMode={bgMode} {...rest} /> | ||
| ); | ||
| } | ||
| return <ficus.View ref={ref} {...rest} />; | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { renderWithTheme as render } from '@test-utils'; | ||
|
|
||
| import { Image } from '.'; | ||
|
|
||
| jest.mock('react-native-toast-message', () => 'Toast'); | ||
|
|
||
| describe('ImageComponent', () => { | ||
| it('renders correctly with given source and alt text', () => { | ||
| const testSource = { uri: 'https://example.com/test-image.jpg' }; | ||
| const testAlt = 'Test Image'; | ||
|
|
||
| const { getByLabelText } = render( | ||
| <Image testID="image-component" source={testSource} alt={testAlt} /> | ||
| ); | ||
|
|
||
| const image = getByLabelText(testAlt); | ||
| expect(image).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('applies the correct image source', () => { | ||
| const testSource = { uri: 'https://example.com/test-image.jpg' }; | ||
|
|
||
| const { getByTestId } = render( | ||
| <Image testID="image-component" source={testSource} alt="Sample Image" /> | ||
| ); | ||
|
|
||
| const image = getByTestId('image-component'); | ||
| expect(image.props.source).toEqual(testSource); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { type NativeFicusProps, ficus } from '../system'; | ||
|
|
||
| export interface ImageProps extends NativeFicusProps<'Image'> {} | ||
|
|
||
| export const Image = ficus('Image'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.