Use container width instead of device width #106
Closed
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.
Currently the device width is used to calculate the width of the calendar, and then each day is /7 of that width. This is a problem on tablets that have large screens. You more than likely will want to reduce the size of the calendar to be less than the width of the screen, especially in landscape.
The following patch uses
onLayout
to figure out the width of the parent container and uses that instead of the device width. It then uses that /7 to for the day width. I had usedflex:1
for the day width, but I also wanted the height to match the width - that way each day doesn't end up being a narrow rectangle depending on the container width.I also fixed a bug where it would always select the current day, even though
this.props.selectedDate
is undefined. This happened becausemoment(undefined)
returns the current date.This patch also makes it easier to do 2 months side-by-side down the road. To do that you would likely: divide
containerWidth
by 2, updategetMonthStack
to render more months, and change the scroll functions to take 2 months into account.