Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

alextychan
Copy link
Contributor

Attribution margins is inconsistent with how it is initialized and is not working as of this writing.

// In MapboxMapBuilder.java; It is initialized with left and bottom margins.
  @Override
  public void setAttributionButtonMargins(int x, int y) {
    options.attributionMargins(new int[] {
            (int) x, //left
            (int) 0, //top
            (int) 0, //right
            (int) y, //bottom
    });
  }

// In MapboxMapController.java
  @Override
  public void setAttributionButtonMargins(int x, int y) {
    mapboxMap.getUiSettings().setAttributionMargins(0, 0, x, y);
  }

Changes:

// In MapboxMapController.java
  @Override
  public void setAttributionButtonMargins(int x, int y) {
    // Use left margins as right margins doesn't work.
    mapboxMap.getUiSettings().setAttributionMargins(x, 0, 0, y); 
  }

@felix-ht
Copy link
Collaborator

can you create a branch and integrate this changes? If you do so i will review it and get it merged.

@felix-ht felix-ht merged commit 84053ab into flutter-mapbox-gl:master Oct 15, 2021
@felix-ht
Copy link
Collaborator

sorry for the accidental merge - please recreate the merge request if you have made the changes for your branch

n8han added a commit that referenced this pull request Nov 2, 2021
This continues the work of PR #615 to fix #261 and #540, and replaces
the changed calculation of #681 with a more general solution.

The underlying issue here is that the attribution button is left-aligned
by default on Android, and right-aligned by default on iOS. The approach
taken in #681 where the margin x value is assumed to represent the left
margin does not generalize to iOS, where it will be a right margin.

Since the alignment / gravity of the button can be configured on each
platform, we can address this problem at its source by exposing this
configuration through flutter-mapbox-gl. Then on Android, we can apply
the button margins same way the compass is positioned, with respect to
its gravity.

I've tested this on iOS and Android with both bottom left and bottom
right attribution buttons. The best option currently is to configure the
attribution button to bottom right, where it falls by default on iOS. In
this way you will have a similar experience on both platforms with a
fully configurable margin.

The mapbox logo's alignment/position is also configurable, should anyone
want to expose it in future.
felix-ht pushed a commit that referenced this pull request Nov 4, 2021
* fix(android): allow android logoViewMargins and attributionButtonMargins to behave similarly to ios

* fix(convert): compass view margin remain the same since theres the gravity and it cant be tested now

* feat(setAttributionButtonMargins): adding variable name to the constant and adjust it to density

* Add attribution button gravity, position normally

This continues the work of PR #615 to fix #261 and #540, and replaces
the changed calculation of #681 with a more general solution.

The underlying issue here is that the attribution button is left-aligned
by default on Android, and right-aligned by default on iOS. The approach
taken in #681 where the margin x value is assumed to represent the left
margin does not generalize to iOS, where it will be a right margin.

Since the alignment / gravity of the button can be configured on each
platform, we can address this problem at its source by exposing this
configuration through flutter-mapbox-gl. Then on Android, we can apply
the button margins same way the compass is positioned, with respect to
its gravity.

I've tested this on iOS and Android with both bottom left and bottom
right attribution buttons. The best option currently is to configure the
attribution button to bottom right, where it falls by default on iOS. In
this way you will have a similar experience on both platforms with a
fully configurable margin.

The mapbox logo's alignment/position is also configurable, should anyone
want to expose it in future.

* Improve switch default behavior

When setting the position of the compass and attribution button, we need
to assume the platform default gravity for those elements if no explicit
value has been provided. An incorrect default was assumed for the
attribution button (copied from the compass), so that is corrected here.

The methods for setting gravity do not require a default since they are
only called if an explicit gravity value has been provided. Those
default cases are removed here.

#731 (comment)

* Rename "gravity" methods in web implementation

This name is not commonly used outside of android. Also, we're
converting to the typed position objects as quickly as possible with
these changes, rather than passing around the int.

#731 (comment)

Co-authored-by: Ching Yaw Hao <[email protected]>
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.

2 participants