-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: calculate width from height #2399
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
db790d5
feat: add test case and try to update Svg element
bohdanprog b9c32bc
feat: handle width and height when we pass percentage and number value
bohdanprog f030107
feat: update test cases
bohdanprog 0bf95be
Merge branch 'main' of github.com:software-mansion/react-native-svg i…
bohdanprog 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
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,61 @@ | ||
import * as React from 'react'; | ||
|
||
import {Alert, StyleSheet, Text, View} from 'react-native'; | ||
import Svg, {Path, Rect} from 'react-native-svg'; | ||
|
||
export default function App() { | ||
return ( | ||
<View style={styles.outer}> | ||
<View style={styles.inner}> | ||
{/* Test Case 1 */} | ||
<Shape width={100} height={100} /> | ||
{/* Test Case 2 */} | ||
<Shape width="50%" /> | ||
{/* Test Case 3 */} | ||
<Shape height="50%" /> | ||
{/* Test Case 4 */} | ||
<Shape width="50%" height="50%" /> | ||
{/* Test Case 5 */} | ||
<Shape /> | ||
{/* Test Case 6 */} | ||
<Shape width={200} /> | ||
{/* Test Case 7 */} | ||
<Svg viewBox="0 0 100 50" width="100%" height="50%"> | ||
<Rect x="0" y="0" width="100" height="50" fill="blue" /> | ||
</Svg> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
function Shape(props: any) { | ||
return ( | ||
<Svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
fill="black" | ||
{...props}> | ||
<Path d="M12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10S2 17.514 2 12 6.486 2 12 2zm0-2C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0zm5.507 13.941c-1.512 1.195-3.174 1.931-5.506 1.931-2.334 0-3.996-.736-5.508-1.931L6 14.434C7.127 16.154 9.2 18 12.001 18c2.8 0 4.872-1.846 5.999-3.566l-.493-.493zM8.5 8a1.5 1.5 0 100 3 1.5 1.5 0 000-3zm7 0a1.5 1.5 0 100 3 1.5 1.5 0 000-3z" /> | ||
</Svg> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
inner: { | ||
flexDirection: 'row', | ||
justifyContent: 'space-evenly', | ||
height: 100, | ||
flex: 1, | ||
backgroundColor: 'green', | ||
}, | ||
|
||
outer: { | ||
marginTop: 100, | ||
flexDirection: 'row', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: 'red', | ||
height: 150, | ||
width: '100%', | ||
}, | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the
%
value is being calculated correctly. For instance, if the screen width is200
and the height is600
, and we have an SVG with a viewBox proportion of1
(such as100/100
) and a width set to50%
, the height should match the width. However, in this implementation, the height ends up being50%
of the screen height, which is300
, rather than the expected100
.