fix viewpager's drag and scrolling

This commit is contained in:
侯歌 2021-06-24 18:47:03 +08:00
parent 119a76cf49
commit 4502b1b1b6
3 changed files with 6 additions and 7 deletions

3
README.md Normal file → Executable file
View File

@ -3,12 +3,13 @@
# **Features:**
* Multi Layer/Multi Window
* Intigated with 30+ UI Components and 15+ Drawables(compatibal with android)
* Integrated with 30+ UI Components and 15+ Drawables(compatibal with android)
* Full compatible with Android
* Smooth Scrolling
* Scrolling with SpringBack Support
# **Screen Shots**
![TextView](docs/images/screenshots/textviews.png)
![ViewPager](docs/videos/viewpager.gif)
# **UI Components:**
* View
* TextView

2
src/gui/widget/view.cc Normal file → Executable file
View File

@ -2238,7 +2238,7 @@ void View::unscheduleDrawable(Drawable& who,Runnable what){
}
void View::unscheduleDrawable(Drawable& who){
LOGD(" %p ",&who);
LOGV(" %p ",&who);
}
ViewGroup*View::getParent()const{

8
src/gui/widget/viewpager.cc Normal file → Executable file
View File

@ -31,6 +31,7 @@ void ViewPager::initViewPager(){
mScroller = new Scroller(context, mInterpolator);
mAdapter = nullptr;
mObserver = nullptr;
mFakeDragging =false;
ViewConfiguration configuration = ViewConfiguration::get(context);
float density = 2.65f;//context.getResources().getDisplayMetrics().density;
@ -1482,7 +1483,7 @@ bool ViewPager::onInterceptTouchEvent(MotionEvent& ev){
float xDiff = std::abs(dx);
float y = ev.getY(pointerIndex);
float yDiff = std::abs(y - mInitialMotionY);
if (dx != 0 && !isGutterDrag(mLastMotionX, dx)
&& canScroll(this, false, (int) dx, (int) x, (int) y)) {
// Nested view has scrollable area under this point. Let it be handled there.
@ -1595,8 +1596,7 @@ bool ViewPager::onTouchEvent(MotionEvent& ev){
if (!mIsBeingDragged) {
int pointerIndex = ev.findPointerIndex(mActivePointerId);
if (pointerIndex == -1) {
// A child has consumed some touch events and put us into an inconsistent
// state.
// A child has consumed some touch events and put us into an inconsistent state.
needsInvalidate = resetTouch();
break;
}
@ -1605,8 +1605,6 @@ bool ViewPager::onTouchEvent(MotionEvent& ev){
float y = ev.getY(pointerIndex);
float yDiff = std::abs(y - mLastMotionY);
LOGV("Moved xy to %f,%f xydiff=%f,%f",x,y,xDiff, yDiff);
if (xDiff > mTouchSlop && xDiff > yDiff) {
LOGV("Starting drag!");
mIsBeingDragged = true;