Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[iOS] Enable change position of UI elements #13556

Merged
merged 25 commits into from
Jan 30, 2019
Merged

Conversation

lloydsheng
Copy link
Contributor

@lloydsheng lloydsheng commented Dec 12, 2018

We need to enable change position of UI elements. This PR was exposed APIs which can be used to customize the position of scalebar, compass, logo and attribution.
Those UI elements can be easily placed on four corners and adjust position with offset.

  • Implement layout codes
  • Add comments and update changelog
  • Manual testing on different devices and systems

ezgif-1-d2a94a343985
/cc @danesfeder @suntony @chriswu42 @jmkiley @macro-shen

@lloydsheng lloydsheng requested a review from a team December 12, 2018 11:30
@lloydsheng lloydsheng changed the title [WIP] Enable change position of UI elements [iOS] Enable change position of UI elements Dec 13, 2018
@lloydsheng lloydsheng requested a review from 1ec5 December 13, 2018 10:16
@lloydsheng
Copy link
Contributor Author

lloydsheng commented Dec 13, 2018

@jmkiley @1ec5 Can you have an 👀 at this PR?

@julianrex julianrex requested review from jmkiley and fabian-guerra and removed request for jmkiley December 13, 2018 15:27
@julianrex
Copy link
Contributor

@fabian-guerra can you take a look at this PR please.

@julianrex
Copy link
Contributor

Thanks @lloydsheng for this PR! I'm excited to see this appear - and think it'll address a lot of existing requests. For example, I believe it could fix #11068.

We do have a number of other constraint related tickets in the backlog - I wonder if we can role some of those into this PR?

@julianrex julianrex requested review from frederoni and removed request for 1ec5 December 13, 2018 15:55
@lloydsheng
Copy link
Contributor Author

lloydsheng commented Dec 17, 2018

Adopt Layour Anchors PR #12147 - I would like to adopt this approach in this PR (or vice-versa). Please take a look.

@julianrex We can't adopt this approach. as we have to cherry pick the PR to iOS 8 branches. I've optimized the performance according to #12144 cc: @frederoni

Performance: #12142 - which reminds me - we should add some tests to this PR to see how performance has changed.

The performance would be better than before, casue it reinstall constraints only when needed now. I'll have tests for comparison.

Add support for contentInsetAdjustmentBehavior: #12143

Can this be done with another PR?

Copy link
Contributor

@fabian-guerra fabian-guerra left a comment

Choose a reason for hiding this comment

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

This looks good just some comments.

  • I realized that if someone adds a negative offset may hide our logo or attribute, not sure if it makes sense add a check for this.
  • Do you think it makes sense handling the case were a developer may inadvertently set the position of an ornament to a place where already exists one thus overlapping?
  • Have you considered exposing the constraint arrays instead? Or make a delegate that returns the ornaments constraints?
  • Could you please add screenshots for multiple size devices and for pre iOS 11.
  • For all public API methods please add their respective log message (take a look at other setter methods for reference).

platform/ios/src/MGLMapView.h Outdated Show resolved Hide resolved
platform/ios/src/MGLMapView.h Outdated Show resolved Hide resolved
platform/ios/src/MGLMapView.h Outdated Show resolved Hide resolved
platform/ios/src/MGLMapView.h Outdated Show resolved Hide resolved
platform/ios/src/MGLMapView.h Outdated Show resolved Hide resolved
platform/ios/src/MGLMapView.h Outdated Show resolved Hide resolved
platform/ios/src/MGLMapView.mm Outdated Show resolved Hide resolved
platform/ios/src/MGLMapView.mm Outdated Show resolved Hide resolved
@fabian-guerra
Copy link
Contributor

This PR fixes #11068

@lloydsheng
Copy link
Contributor Author

lloydsheng commented Dec 21, 2018

@fabian-guerra

Do you think it makes sense handling the case were a developer may inadvertently set the position of an ornament to a place where already exists one thus overlapping?

It's easy to find out if there is overlapping.

Have you considered exposing the constraint arrays instead? Or make a delegate that returns the ornaments constraints?

Yes, but I think property setting APIs are more simple and easy to use.

Could you please add screenshots for multiple size devices and for pre iOS 11.

Screenshots for multiple size devices and systems

Device ❌ Navigation Bar ✅ Navigation Bar
iPhone XS Max - 12.1 iphonexsmax-12 1-without-navigationbar iphonexsmax-12 1-with-navigationbar
iPhone X - 12.1 iphonex-12 1-without-navigationbar iphonex-12 1-with-navigationbar
iPhone 6 Plus - 9.0 iphone6splus-9 0-without-navigationbar iphone6splus-9 0-with-navigationbar
iPhone5 9.0 iphone5-9 0-without-navigationbar iphone5-9 0-with-navigationbar

/cc @jmkiley @chriswu42

@friedbunny
Copy link
Contributor

Layout Anchors

Adopt Layour Anchors PR #12147 - I would like to adopt this approach in this PR (or vice-versa). Please take a look.

@julianrex We can't adopt this approach. as we have to cherry pick the PR to iOS 8 branches. I've optimized the performance according to #12144 cc: @frederoni

I support @julianrex’s request — the “new” layout anchors API represents a significant improvement in both performance (according to Apple, anyway) and concision, and there’s no reason not to adopt it in the mainline SDK.

Tests

The screenshots are much appreciated, @lloydsheng, but this PR currently has a noticeable lack of automated/reproducible tests. Ornament layout has been a consistent source of bugs over the years and we should be extremely careful when making significant changes to it. (E.g., lack of tests is why #12147 hasn’t been merged yet.)

@frederoni
Copy link
Contributor

We should be able to merge this PR with #12147
What we need is one extra layer of abstraction to support iOS 8. I'm thinking something along the lines of -[UIView(MGLLayoutAnchor) mgl_constraintEqualTo:constant:], MGLLayoutAnchor would have to be fully defined on iOS 8 but it would only act as an alias to NSLayoutAnchor when provided by the OS.

@fabian-guerra
Copy link
Contributor

@julianrex @friedbunny could you please explain which parts of #12147 this PR should include? So far I've seen safeAreaLayoutGuide + anchors on both; with a major difference that this pr allows ornaments get placed elsewhere.

I agree that there are missing automated tests. Do you think that checking the constraint values would be enough? Or what do you have in mind?

Thanks @lloydsheng for your patience, as Jason already pointed out ornaments placement has caused some issues in the past that's why the team has been extra careful reviewing the pr.

@lloydsheng
Copy link
Contributor Author

What we need is one extra layer of abstraction to support iOS 8.

@frederoni I prefer the straightforward layout codes the PR adopted. Cause the map view only has few ornaments and the UI hierarchy is simple. I already abstracted several methods to avoid duplication of code. As @fabian-guerra saild. It actually adopted safeAreaLayoutGuide, anchors for concision and + (void)activateConstraints: for better performance. Is it worth adding some categories/classes for a extra layer of abstraction to support iOS 8?

Jason already pointed out ornaments placement has caused some issues in the past that's why the team has been extra careful reviewing the pr.

@fabian-guerra @friedbunny I understand that. I can submit the demo code I used for manual testing if it's needed. This feature was strongly required by our main customers in China. I've spent many time to test it on different systems and screens of different sizes to make sure it works well. If you have any ideas for automated/reproducible tests please tell me. 🙏

cc @chriswu42

@fabian-guerra
Copy link
Contributor

@fabian-guerra @friedbunny I understand that. I can submit the demo code I used for manual testing if it's needed. This feature was strongly required by our main customers in China. I've spent many time to test it on different systems and screens of different sizes to make sure it works well. If you have any ideas for automated/reproducible tests please tell me.

Unless @friedbunny has something different in mind I think you could add the manual test code as part of the iosapp & test each ornament's frame in MGLMapViewTests.

@lloydsheng
Copy link
Contributor Author

lloydsheng commented Jan 10, 2019

@fabian-guerra @friedbunny I found that there were some tests for ornament layout in this file https://github.com/mapbox/mapbox-gl-native/blob/master/platform/ios/test/MGLMapViewLayoutTests.m. I will add more tests of this type to test different positions and offsets for each ornament.

@fabian-guerra
Copy link
Contributor

I will add more tests of this type to test different positions and offsets for each ornament.
👍🏼@lloydsheng

@lloydsheng
Copy link
Contributor Author

@fabian-guerra @friedbunny I've added the demo code and tests. please take a look at it.

@@ -6313,6 +6413,7 @@ - (void)updateScaleBar
if ( ! self.scaleBar.hidden)
{
[(MGLScaleBar *)self.scaleBar setMetersPerPoint:[self metersPerPointAtLatitude:self.centerCoordinate.latitude]];
[self installScaleBarConstraints];
Copy link
Contributor

Choose a reason for hiding this comment

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

Placing this here can cause installScaleBarConstraints be to called many times a second (i.e., every time the camera changes and the scale is updated). Constantly updating the constraints in this way seems like it could have a negative effect on performance — can/should this be avoided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have a better way at the moment. As constraints of the scalebar should be updated every time when metersPerPoint value changed.

platform/ios/src/MGLMapView.mm Outdated Show resolved Hide resolved
platform/ios/src/MGLMapView.mm Outdated Show resolved Hide resolved
platform/ios/src/MGLMapView.mm Outdated Show resolved Hide resolved
platform/ios/app/MBXOrnamentsViewController.m Outdated Show resolved Hide resolved
@@ -0,0 +1,92 @@
#import "MBXOrnamentsViewController.h"
Copy link
Contributor

@fabian-guerra fabian-guerra Jan 17, 2019

Choose a reason for hiding this comment

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

This example should be moved once this PR lands to https://github.com/mapbox/ios-sdk-examples repo as we use the latter for manual testing (with Objc / Swift versions).

@lloydsheng
Copy link
Contributor Author

@fabian-guerra @friedbunny I've updated, Thanks for your comments.

@lloydsheng
Copy link
Contributor Author

@fabian-guerra @friedbunny Can you please take a look at this PR?

Copy link
Contributor

@fabian-guerra fabian-guerra left a comment

Choose a reason for hiding this comment

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

This PR is almost done, I just added a comment regarding what Jason was asking.

platform/ios/src/MGLMapView.mm Outdated Show resolved Hide resolved
@lloydsheng
Copy link
Contributor Author

@fabian-guerra @friedbunny @frederoni I've adopted layout anchors and removed iOS8 compatible codes. Please take a look at it. 🙏

Copy link
Contributor

@fabian-guerra fabian-guerra left a comment

Choose a reason for hiding this comment

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

👍🏼

@lloydsheng lloydsheng merged commit e22d28c into master Jan 30, 2019
@friedbunny friedbunny added the iOS Mapbox Maps SDK for iOS label Jan 30, 2019
@friedbunny friedbunny added this to the release-k milestone Jan 30, 2019
@friedbunny friedbunny deleted the lloyd-ui-position branch January 30, 2019 19:27
lloydsheng added a commit that referenced this pull request Feb 2, 2019
julianrex pushed a commit that referenced this pull request Feb 5, 2019
julianrex added a commit that referenced this pull request Feb 5, 2019
@lloydsheng lloydsheng restored the lloyd-ui-position branch February 11, 2019 01:46
lloydsheng added a commit that referenced this pull request Mar 20, 2019
…of mapview ornaments (#13863)

* Cherry-pick PR #13556 to adding options to customize positions of mapbox ornaments
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants