React-native layout with center element and bottom container that should grow with children - react-native

I have a layout that keeps occurring in my codebase, that I'm not able to style properly with react-native flex only.
I want to have a top and bottom container which initially should both take half the screen space. The bottom container should grow with it's children and the top container should shrink if need be.
I've created a snack with the code here, where the layout behaves as it should, but it's using a workaround via onLayout: https://snack.expo.io/#domir/center-problem
The same problem is easily solved in web via flex: 1 on both containers. In react-native if I have flexGrow: 1 on both of them, they only divide leftover whitespace.
E.g. Currently for a display height 1000 a top container will get 400 while bottom container will get 400 + 200 when a 200 child is placed there when using flexGrow: 1. What I want is both to get 500 until the bottom container has 3 children with 200 each. Then I want the top container to get 400 and the bottom to have 600.

Not sure if there's a way to solve this JUST with flex (probably not) - and I'm not sure what your requirements are, but here's a way to solve that without using onLayout but instead just use maxHeight percentages:
https://snack.expo.io/#sudoplz/center_problem_maybe_solved
All I actually did was I used the existing counter value you had in that snack, to modify the input of maxHeight
The top parent is now styled like that:
maxHeight: `${Math.min(50, ITEM_HEIGHT - counter * ITEM_HEIGHT_PERCENTAGE)}%`
which means that until the bottom parent is full, it's max value will be 50%, as soon as it's full, the maxHeight becomes less and less gradually (depending on he number of children on the bottom view)
In my snack I also got rid of some unnecessary views you had, not sure why they were there.
Here's how that looks like now:
Would that work for you?

As you can see below, the maxHeight solution does not work quite well on a real device. Some of the lower boxes are cropped off or overflow the screen.
Although the solution does not have to be with flex only, I do have a flexible container at the bottom. It contains text and a varying amount of error messages. The yellow space would contain whitespace and the green container would contain some text input. On large screens, this is not a problem, but for small devices, the error messages can take up quite a bit of space and I'm not able to calculate the size of the lower parts in advance.

Related

Fix width to 50/50 in a splitpane made from FluentUI Stack component

I am using a stack component to make a split pane. I wanted to make it such that left side has 50% screen space and right side has the remaining 50%. However the problem is that the 2 panes are not equal width from beginning, and as text is added to the left component it starts to grow in width.
How do i fix this so that they always share width equally (50%/50%) ?
Here is a CSB illustrating the issue:
https://codesandbox.io/s/jolly-faraday-lek5h?file=/src/App.tsx

Android: Horizontal RecyclerView Layout with Cards is cutting off the bottom of larger layouts

It seems that the later cards (1st photo) are being cropped to the size of the biggest card that’s in the initial view (see card marked with red in 2nd photo). All the cards that would be bigger than that have the bottom of the view cut off/wrapped. I’m using a MaterialCardView with a ConstraintLayout inside that holds all the views you see in the card. The CardView, ConstraintLayout, and RecyclerView all have layout_height=wrap_content. I've tried changing setHasFixedSize() and a number of other random things around layout_height/width.
Any ideas to why that would be happening?
probably you put a android:layout_marginBottom on red marked card and using that for all of your cards . that will prevent the cards to show they're full content .
you can make you font or images smaller or change that android:layout_marginBottom

Create A view with fixed percentage of width in all orientations in React-Native

I want to create a view - that contains a Card - always with '90%' width of the window, whenever the device is vertical or horizontal, or Component is in a parent or not.
What I tried:
1 Using percentage
( width: '90%'):
It works well if I use my card separately on the main view of my screen, but when I use my card on a horizontal ScrollView with other cards I can see many cards, but I want to see only one card before scrolling.
2 Using React.Dimensions
( Dimensions.get('window').width*0.9 with some padding) :
It works perfectly when I use a card separately or even with many inside a scrollView but when I change the orientation of the screen it takes less width of the screen than '90%'.
3 Using flex basis based on this answer
Is there any better way to achieve my goal?
You might wanna look at this package https://github.com/marudy/react-native-responsive-screen
This package doesn't require any orientation change support. It's just one file actually, so you might wanna take a look at that

Bootstrap 3 navbar jumping onto two lines rather than collapsing?

Think I'm missing the obvious here, but I have a Bookstrap 3 navbar that works great in desktop view but as I squeeze the width and it gets to tablet size rather than collapsing into the toggle menu it's jumping the menu onto two lines:
http://www.doorsets.org.uk/
I've tried reducing the text size in the navbar via a media query but that isn't solving it.
What am I missing?
Appreciate it. Thank you.
NJ
One solution might be to change the point at which the navbar collapses, you can do this by creating a customized Bootstrap and setting the #grid-float-breakpoint to a larger number.
This variable unfortunately also influences the dt and dd inside a .dl-horizontal which might be a problem.
If you want to use a media query to reduce the font-size you can use the .navbar-default .navbar-nav > li > a selector. It however needs to become 9px at the smallest viewport size to still stay on a single row which is quite unreadable.
From the Bootstrap documentation:
Overflowing content
Since Bootstrap doesn't know how much space the content in your navbar needs, you might run into issues with content wrapping into a second row. To resolve this, you can:
Reduce the amount or width of navbar items.
Hide certain navbar items at certain screen sizes using responsive utility classes.
Change the point at which your navbar switches between collapsed and horizontal mode. Customize the #grid-float-breakpoint variable or add your own media query.
It goes on to say:
Changing the collapsed mobile navbar breakpoint
The navbar collapses into its vertical mobile view when the viewport is narrower than #grid-float-breakpoint, and expands into its horizontal non-mobile view when the viewport is at least #grid-float-breakpoint in width. Adjust this variable in the Less source to control when the navbar collapses/expands. The default value is 768px (the smallest "small" or "tablet" screen).

Leaflet map and bootstrap 3

Please have a look at http://www.bootply.com/133473.
I have at least a couple of problems and I didn't find any solution up to now...
First problem:
The leaflet map is 0px height and the next row is not in the correct position.
Second problem (but maybe it is related to the first one):
On a small device the width of the map is the full width but I'd like to have a margin and I wasn't able to get it (I tried but margin-left, margin-right and padding-left, padding-right...) and of course the text row is superimposed to the map and that's not what I want...
Looking at your bootply posting, it looks like your first problem was solved (I see the map so the height must not be 0px).
As for your second problem, it is the Bootstrap Editor that is not able to show your app on smaller screens. This problem may go away when you view your app on its own web page.