-
-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support "object-fit" CSS property for images
- Loading branch information
Showing
8 changed files
with
55 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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
34 changes: 33 additions & 1 deletion
34
packages/render-html/src/elements/extractImageStyleProps.ts
This file contains 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,10 +1,42 @@ | ||
import { ImageStyle } from 'react-native'; | ||
import { WebBlockStyles } from '@native-html/transient-render-engine'; | ||
|
||
import pick from 'ramda/src/pick'; | ||
|
||
const extractImageStyleProps = pick<keyof ImageStyle>([ | ||
const extractProps = pick<keyof ImageStyle>([ | ||
'resizeMode', | ||
'tintColor', | ||
'overlayColor' | ||
]); | ||
|
||
function mapObjectFit(objectFit: WebBlockStyles['objectFit']) { | ||
let resizeMode: ImageStyle['resizeMode']; | ||
switch (objectFit) { | ||
case 'contain': | ||
case 'cover': | ||
resizeMode = objectFit; | ||
break; | ||
case 'fill': | ||
resizeMode = 'stretch'; | ||
break; | ||
case 'scale-down': | ||
resizeMode = 'contain'; | ||
break; | ||
default: | ||
return null; | ||
} | ||
return { resizeMode }; | ||
} | ||
|
||
function extractImageStyleProps( | ||
style: any, | ||
objectFit?: WebBlockStyles['objectFit'] | ||
) { | ||
const resizeModeFromFit = objectFit ? mapObjectFit(objectFit) : null; | ||
return { | ||
...extractProps(style), | ||
...resizeModeFromFit | ||
}; | ||
} | ||
|
||
export default extractImageStyleProps; |
This file contains 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 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 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 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 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