After drawing a bit of inspiration from ENJOY CSS Shapes We decided to see if I could remake some of these shapes with a subset of css.
Of course we have to access react-design
here so drawing shapes is pretty mush easy but my way is to see if I can just use normal Views
and to get all the shapes in React
Added some of the shapes but got crazy! But most of the shapes are did :-)
- I wish border-radius worked a little more like the web
- Box Shadow would be nice to have as well.
- Skew transform would be a nice to have.
- Just use SVGs…
Pretty simple…
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Nothing too crazy here either
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
One note to mention about border radius is that it doesn’t work like the web. So if you go more than 50% you’ll start forming a weird diamondy shape.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Border radius wasn’t working, lets just do a circle and scale it…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
CSS border triangles still work in React Native.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Here we get to cheat a bit. You could do this on the web too, but rather than adjust the borders we’ll just rotate it.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Again we’ll cheat here and go for the rotation!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Well we don’t have the ability to do pseudo elements but they were just hacks anyway so we’ll just create a wrapping View
with 2 elements and style them.
Now this is not exactly the same, and it’s partially due to the way border-radius
are managed in react-native vs the web but it’s closeish.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
The difference with this one is we had to double our width. Why? I don’t know.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
If only we had skew. :( Luckily we have the triangles we created earlier.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
These Triangles sure are coming in handy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Yaye TriangleUp
is killing it. This one is REALLY hacky with the placement, could use some fine tuning.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
No TriangleUp
here but we could have used a Corner Triangle with rotate.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
2 Triangles and a square. Everything is just shapes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
I attempted copied the css on this one but it required setting a background color, so I did 4 bars and just rotated them. Slightly more markup but this is just for fun.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
This one is easy since well I already had it done for my previous tutorial.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Width and border radius all work oddly together. So baby infinity? Scale it up if you want it bigger.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
This was more than just a rotated square. Am I missing something?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Just 2 triangles, thought this one was going to be harder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
Another 2 triangles that could have been the same and rotated. This way works too.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
The top could have been used for the octagon, I chose a different way though.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
Circular things are hard to do in RN. This is eggish.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
This one is so simple but always so fun.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
This one is also simple, triangle and a rounded square.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
I will admit this one confused be a little bit, then I realized it’s just a couple of rotated squares.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
Just like the 12, but one less square and different rotations. Only thing here is because the pseudo element was positionined relative to the first 20 degree rotation and ours isn’t we’ll just bump it up to 155.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
This one I don’t like because you can’t accomplish it without setting a background. Ohwell. Also weird border issue causing outlines.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
Remember, always add backgroundColor: 'transparent'
when you are overlapping things.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
WUTTTTTTTTTTT
Stupid border radius making this one hard. We’ll just use a bunch of ovals.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
Once again we don’t have skew, but we’ll use triangles. Also magical negative scale to flip stuff around!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
Border around a circle with a stick. Nothing to it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
This one seems appropriate but couldn’t get it to work well. I attempted it and failed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
Box shadow…
The one on css-tricks inferred a background, we’ll just flip it around and say the center is transparent and the outer triangles are red.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
Had to modify the css on this one a bit to get the same look, 70 => 55.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
More of a plus then a cross.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
Base… Home .. Home Base, whichever all the same.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
Wow what a fun waste of time. Modeling React Native after the web spec is of course a great idea, I just wish it conformed a little nicer on border radius.
Also I hate geometry now.
Live Code https://rnplay.org/apps/58FEmw
I’m not posting the full code here because it’s just too long.
Tagged under Reference