-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[iOS] Enable change position of UI elements #13556
Conversation
@fabian-guerra can you take a look at this PR please. |
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 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
The performance would be better than before, casue it reinstall constraints only when needed now. I'll have tests for comparison.
Can this be done with another PR? |
There was a problem hiding this 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).
This PR fixes #11068 |
It's easy to find out if there is overlapping.
Yes, but I think property setting APIs are more simple and easy to use.
Screenshots for multiple size devices and systems
/cc @jmkiley @chriswu42 |
Layout Anchors
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. TestsThe 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.) |
We should be able to merge this PR with #12147 |
@julianrex @friedbunny could you please explain which parts of #12147 this PR should include? So far I've seen 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. |
@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
@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 |
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 |
@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 @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]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@@ -0,0 +1,92 @@ | |||
#import "MBXOrnamentsViewController.h" |
There was a problem hiding this comment.
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).
@fabian-guerra @friedbunny I've updated, Thanks for your comments. |
@fabian-guerra @friedbunny Can you please take a look at this PR? |
There was a problem hiding this 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.
@fabian-guerra @friedbunny @frederoni I've adopted layout anchors and removed iOS8 compatible codes. Please take a look at it. 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
c8fde61
to
f46280d
Compare
This reverts commit e22d28c.
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.
/cc @danesfeder @suntony @chriswu42 @jmkiley @macro-shen