Skip to content
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

fix: Vertically center the map on mobile when opening it #149

Merged
merged 3 commits into from
Jul 5, 2022

Conversation

PolariTOON
Copy link
Contributor

This is an approximation. This would likely need to take into account the minimum height of the bottom sheet to be perfect, but it's not exposed by the component.

@bundlemon
Copy link

bundlemon bot commented Jun 23, 2022

BundleMon

Files updated (1)
Status Path Size Limits
app/coachco2.(hash).js
39.61KB (+21B +0.05%) -
Unchanged files (3)
Status Path Size Limits
vendors/coachco2.(hash).js
597.51KB -
vendors-coachco2.(hash).(hash).min.css
31.89KB -
app-coachco2.(hash).min.css
140B -

Total files change +21B 0%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@Crash--
Copy link
Contributor

Crash-- commented Jun 23, 2022

but it's not exposed by the component.

Do you have a ref on this component? Or can you add one? Something like: ref.current.clientHeight

Copy link
Contributor

@JF-Cozy JF-Cozy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ça me paraît bizarre qu'en changeant la valeur de mapPanRatio ça fonctionne toujours pour les trajets "horizontaux" 🤔 c'est le fait d'avoir remplacer le panBy par paddingBottomRight qui fait que ??

@PolariTOON
Copy link
Contributor Author

Do you have a ref on this component? Or can you add one? Something like: ref.current.clientHeight

I can likely get a ref to the BottomSheet, but even so, i don't really need its current total height, but maybe something like the height of the visible part of the BottomSheet when it is collapsed (and it is not collapsed at this point). I can not directly read it, given it is an internal state of the component. I would have to parse the transform property instead which does not seem straightforward.

ça me paraît bizarre qu'en changeant la valeur de mapPanRatio ça fonctionne toujours pour les trajets "horizontaux" thinking c'est le fait d'avoir remplacer le panBy par paddingBottomRight qui fait que ??

Voici ce que dit la documentation à propos de l'option paddingTopLeft (de même pour paddingBottomRight) :

Sets the amount of padding in the top left corner of a map container that shouldn't be accounted for when setting the view to fit bounds. Useful if you have some control overlays on the map like a sidebar and you don't want them to obscure objects you're zooming to.

C'est typiquement notre cas de figure. Ça permet de réserver un certain espace et de centrer le trajet au sein de l'espace restant.

Exemple si la taille medium de la BottomSheet est initialisée à 2/3 (ce qui est le cas actuellement) :

Exemple si la taille medium de BottomSheet était initialisée à 1/3 :

À noter que si on rétracte la BottomSheet, ça ne recentre pas la carte pour autant, c'est seulement en arrivant sur la page.

@JF-Cozy
Copy link
Contributor

JF-Cozy commented Jun 24, 2022

il nous reste un mini souci avec un trajet
image

@PolariTOON
Copy link
Contributor Author

There is still a small initial vertical shift when opening the map that disappears once the viewport is resized. This seems to be due to how we observe the toolbar height (replacing the variable with a magic number fixes the issue), but I did not manage to find any strategy with the right hooks to measure it at the right time. This might require changes to cozy-ui, so we should likely keep the work for another PR.

@PolariTOON PolariTOON requested a review from JF-Cozy July 4, 2022 08:28
@JF-Cozy
Copy link
Contributor

JF-Cozy commented Jul 4, 2022

@PolariTOON ok merci pour le retour. Je pense qu'on peut valider ici et ouvrir une issue en parallèle sur cozy-ui 👍 Je te laisse gérer ça ?

mapL.fitBounds(geojsonL.getBounds(), {
paddingBottomRight: [0, mapL.getSize().y * mapPanRatio]
const bounds = geojsonL.getBounds()
const padding = 16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • on peut sortir le const padding = 16 en constant hors du composant
  • si c'est en fix en rapport à l'issue cozy-ui, on peut créer l'issue et ajouter le lien vers l'issue ici en // TODO:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non, c'est pas en fix, c'est juste par rapport à ta revue précédente, ça permet de compenser l'épaisseur du trait du trajet et de ses marqueurs au début et à la fin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le seul fix que j'ai trouvé pour l'instant ça serait de précalculer la hauteur :

 mapContainer: {
-  height: `calc(100vh - ${toolbarHeight}px - env(safe-area-inset-bottom))`
+  height: "calc(100vh - 47px - env(safe-area-inset-bottom))"
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai ouvert un ticket à ce propos ici : cozy/cozy-ui#2185

@PolariTOON PolariTOON force-pushed the mobile-map-vertical-center branch from 7a15845 to d7672e7 Compare July 4, 2022 14:03
@PolariTOON PolariTOON force-pushed the mobile-map-vertical-center branch from d7672e7 to 92bb171 Compare July 5, 2022 08:03
@PolariTOON PolariTOON merged commit cd5cc30 into master Jul 5, 2022
@PolariTOON PolariTOON deleted the mobile-map-vertical-center branch July 5, 2022 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants