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

Add extension function for locationComponent to support show and hide arrow bearing image. #1012

Merged
merged 5 commits into from
Jan 11, 2022

Conversation

Chaoba
Copy link
Contributor

@Chaoba Chaoba commented Dec 21, 2021

Summary of changes

This PR adds an extension function. Users can show or hide the bearing image by switching LocationPuck instance getting from it.

Record_2022-01-10-10-38-33_e38d0e4b1b9ec9f0e9b280cd077e482c.mp4

User impact (optional)

Pull request checklist:

  • Briefly describe the changes in this PR.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality. If tests were not written, please explain why.
  • Optimize code for java consumption (@JvmOverloads, @file:JvmName, etc).
  • Add example if relevant.
  • Document any changes to public APIs.
  • Apply changelog label ('breaking change', 'bug 🪲', 'build', 'docs', 'feature 🍏', 'performance ⚡', 'testing 💯') or use the label 'skip changelog'
  • Add an entry inside this element for inclusion in the mapbox-maps-android changelog: <changelog>Add extension function for locationComponent to support show and hide arrow bearing image.</changelog>.
  • If this PR is a v10.[version] release branch fix / enhancement, merge it to main firstly and then port to v10.[version] release branch.

Fixes: < Link to related issues that will be fixed by this pull request, if they exist >

PRs must be submitted under the terms of our Contributor License Agreement CLA.

@Chaoba Chaoba self-assigned this Dec 21, 2021
@Chaoba Chaoba marked this pull request as ready for review December 21, 2021 12:09
@Chaoba Chaoba requested a review from a team as a code owner December 21, 2021 12:09
@kiryldz
Copy link
Contributor

kiryldz commented Jan 4, 2022

@Chaoba can we add visuals in PR description here?

@Chaoba Chaoba changed the title Add showBearingImage config for locationComponent. Add puck styles for locationComponent. Jan 10, 2022
@Chaoba Chaoba changed the title Add puck styles for locationComponent. Add extension functions for locationComponent to support show and hide arrow bearing image. Jan 10, 2022
@Chaoba Chaoba changed the title Add extension functions for locationComponent to support show and hide arrow bearing image. Add extension function for locationComponent to support show and hide arrow bearing image. Jan 11, 2022
…ponentActivity.kt

Co-authored-by: Kiryl Dzehtsiarenka <kiryl.dzehtsiarenka@mapbox.com>
@Chaoba Chaoba merged commit 4c663db into main Jan 11, 2022
@Chaoba Chaoba deleted the kl-location-puck-bearing branch January 11, 2022 13:16
Comment on lines +28 to +60
return LocationPuck2D(
topImage = ResourcesCompat.getDrawable(context.resources, R.drawable.mapbox_user_icon, null),
bearingImage = ResourcesCompat.getDrawable(
context.resources,
R.drawable.mapbox_user_bearing_icon,
null
),
shadowImage = ResourcesCompat.getDrawable(
context.resources,
R.drawable.mapbox_user_stroke_icon,
null
)
)
} else {
return LocationPuck2D(
topImage = ResourcesCompat.getDrawable(
context.resources,
R.drawable.mapbox_user_icon,
null
),
bearingImage = ResourcesCompat.getDrawable(
context.resources,
R.drawable.mapbox_user_stroke_icon,
null
),
shadowImage = ResourcesCompat.getDrawable(
context.resources,
R.drawable.mapbox_user_icon_shadow,
null
)
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

val bearingImageId = if (withBearing) R.drawable.mapbox_user_bearing_icon else R.drawable.mapbox_user_stroke_icon

val shadowImage =  if (withBearing) R.drawable.mapbox_user_stroke_icon else R.drawable.mapbox_user_icon_shadow

return LocationPuck2D(
      topImage = ResourcesCompat.getDrawable(context.resources, R.drawable.mapbox_user_icon, null),
      bearingImage = ResourcesCompat.getDrawable(
        context.resources,
        bearingImageId,
        null
      ),
      shadowImage = ResourcesCompat.getDrawable(
        context.resources,
        shadowImage,
        null
      )
    )

also small extension for context:

fun Context.getCompatDrawable(resId:Int) = ResourcesCompat.getDrawable(
        this,
        resId,
        null
      )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants