https://github.com/commit451/translationviewdraghelper
ViewDragHelper that accounts for view translations
https://github.com/commit451/translationviewdraghelper
android translation
Last synced: 8 months ago
JSON representation
ViewDragHelper that accounts for view translations
- Host: GitHub
- URL: https://github.com/commit451/translationviewdraghelper
- Owner: Commit451
- License: apache-2.0
- Created: 2016-05-15T17:58:25.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2024-01-22T05:53:01.000Z (about 2 years ago)
- Last Synced: 2025-04-26T02:52:39.538Z (11 months ago)
- Topics: android, translation
- Language: Kotlin
- Size: 151 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# TranslationViewDragHelper
A version of [ViewDragHelper](https://developer.android.com/reference/androidx/customview/widget/ViewDragHelper) which accounts for X and Y translations.
[](https://maven-badges.herokuapp.com/maven-central/com.commit451/translationviewdraghelper)
## Gradle
```groovy
dependencies {
implementation("com.commit451:translationviewdraghelper:latest.release.here")
}
```
# Usage
If you have ever used a `ViewDragHelper` before, you may have noticed that if you were to translate your views using `View.setX()` or `View.setY()`, your helper would no longer correctly allow you to drag the views. This library seeks to correct this. Usage is identical to `ViewDragHelper` usage:
```kotlin
val callback = TranslationViewDragHelper.Callback {
override fun tryCaptureView(child: View, pointerId: Int): Boolean {
// Any children can be captured
return true
}
override fun clampViewPositionHorizontal(child: View, left: Int, dx: Int): Int {
// allow full movement along horizontal axis
return left
}
override fun clampViewPositionVertical(child: View, top: Int, dy: Int): Int {
// allow full movement along vertical axis
return top
}
}
val viewDragHelper = TranslationViewDragHelper.create(
viewGroup,
1.0f,
callback
)
```
See the sample [custom view](https://github.com/Commit451/TranslationViewDragHelper/blob/master/app/src/main/java/com/commit451/betterviewdraghelper/sample/AllowsForDragFrameLayout.java) for a more complete example
# Basis
The current version of this helper is derived from `ViewDragHelper` source from `1.0.0` of the `androidx.customview` library. Due to private constructor access on ViewDragHelper, the source has to be copied out into the `TranslationViewDragHelper`. You can check to see if anything has changed [here](https://android.googlesource.com/platform/frameworks/support/+log/a9ac247af2afd4115c3eb6d16c05bc92737d6305/customview/src/main/java/androidx/customview/widget/ViewDragHelper.java)
License
--------
Copyright 2024 Commit 451
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.