~macslow/unity8/swipe-dismiss-snap-decisions

« back to all changes in this revision

Viewing changes to qml/Stages/PhoneStage.qml

Merge from wizard-import

Show diffs side-by-side

added added

removed removed

Lines of Context:
145
145
 
146
146
        // Those markers mark the various positions in the spread (ratio to screen width from right to left):
147
147
        // 0 - 1: following finger, snap back to the beginning on release
148
 
        property real positionMarker1: 0.3
 
148
        property real positionMarker1: 0.2
149
149
        // 1 - 2: curved snapping movement, snap to app 1 on release
150
 
        property real positionMarker2: 0.45
 
150
        property real positionMarker2: 0.3
151
151
        // 2 - 3: movement follows finger, snaps back to app 1 on release
152
 
        property real positionMarker3: 0.6
 
152
        property real positionMarker3: 0.35
153
153
        // passing 3, we detach movement from the finger and snap to 4
154
154
        property real positionMarker4: 0.9
155
155
 
156
156
        // This is where the first app snaps to when bringing it in from the right edge.
157
 
        property real snapPosition: 0.75
 
157
        property real snapPosition: 0.7
158
158
 
159
159
        // Phase of the animation:
160
160
        // 0: Starting from right edge, a new app (index 1) comes in from the right
178
178
            case 1:
179
179
                if (shiftedContentX < width * positionMarker2) {
180
180
                    phase = 0;
181
 
                } else if (shiftedContentX >= width * positionMarker4) {
 
181
                } else if (shiftedContentX >= width * positionMarker4 && !spreadDragArea.dragging) {
182
182
                    phase = 2;
183
183
                }
184
184
                break;
270
270
 
271
271
            Repeater {
272
272
                id: spreadRepeater
 
273
                objectName: "spreadRepeater"
273
274
                model: ApplicationManager
274
275
                delegate: TransformedSpreadDelegate {
275
276
                    id: appDelegate
286
287
                    otherSelected: spreadView.selectedIndex >= 0 && !selected
287
288
                    interactive: !spreadView.interactive && spreadView.phase === 0
288
289
                            && spreadView.shiftedContentX === 0 && root.interactive && index === 0
289
 
                    swipeToCloseEnabled: spreadView.interactive
 
290
                    swipeToCloseEnabled: spreadView.interactive && !snapAnimation.running
290
291
                    maximizedAppTopMargin: root.maximizedAppTopMargin
291
292
                    dropShadow: spreadView.active ||
292
293
                                (priv.focusedAppDelegate && priv.focusedAppDelegate.x !== 0)
367
368
                        if (spreadView.phase == 0 && index < 2) {
368
369
                            if (progress < spreadView.positionMarker1) {
369
370
                                return progress;
370
 
                            } else if (progress < spreadView.positionMarker1 + snappingCurve.period){
371
 
                                return spreadView.positionMarker1 + snappingCurve.value * 3;
 
371
                            } else if (progress < spreadView.positionMarker1 + 0.05){
 
372
                                // p : 0.05 = x : pm2
 
373
                                return spreadView.positionMarker1 + (progress - spreadView.positionMarker1) * (spreadView.positionMarker2 - spreadView.positionMarker1) / 0.05
372
374
                            } else {
373
375
                                return spreadView.positionMarker2;
374
376
                            }
380
382
                    visible: (progress >= 0 && progress < 1.7) ||
381
383
                             (isDash && priv.focusedAppDelegate.x !== 0)
382
384
 
383
 
                    EasingCurve {
384
 
                        id: snappingCurve
385
 
                        type: EasingCurve.Linear
386
 
                        period: 0.05
387
 
                        progress: appDelegate.progress - spreadView.positionMarker1
388
 
                    }
389
 
 
390
385
                    Binding {
391
386
                        target: appDelegate
392
387
                        property: "orientation"
425
420
        id: spreadDragArea
426
421
        objectName: "spreadDragArea"
427
422
        direction: Direction.Leftwards
428
 
        enabled: spreadView.phase != 2 && root.spreadEnabled
 
423
        enabled: (spreadView.phase != 2 && root.spreadEnabled) || dragging
429
424
 
430
425
        anchors { top: parent.top; right: parent.right; bottom: parent.bottom }
431
426
        width: root.dragAreaWidth
432
427
 
433
 
        // Sitting at the right edge of the screen, this EdgeDragArea directly controls the spreadView when
434
 
        // attachedToView is true. When the finger movement passes positionMarker3 we detach it from the
435
 
        // spreadView and make the spreadView snap to positionMarker4.
436
 
        property bool attachedToView: true
437
 
 
438
428
        property var gesturePoints: new Array()
439
429
 
440
430
        onTouchXChanged: {
443
433
                spreadView.phase = 0;
444
434
                spreadView.contentX = -spreadView.shift;
445
435
            }
446
 
            if (dragging && status == DirectionalDragArea.Recognized && attachedToView) {
 
436
            if (dragging && status == DirectionalDragArea.Recognized) {
447
437
                // Gesture recognized. Let's move the spreadView with the finger
448
 
                var finalX = Math.min(touchX + width, width);
449
 
                spreadView.contentX = -finalX + spreadDragArea.width - spreadView.shift;
450
 
            }
451
 
            if (attachedToView && spreadView.shiftedContentX >= spreadView.width * spreadView.positionMarker3) {
452
 
                // We passed positionMarker3. Detach from spreadView and snap it.
453
 
                attachedToView = false;
454
 
                spreadView.snap();
 
438
                var dragX = Math.min(touchX + width, width); // Prevent dragging rightwards
 
439
                dragX = -dragX + spreadDragArea.width - spreadView.shift;
 
440
                // Don't allow dragging further than the animation crossing with phase2's animation
 
441
                var maxMovement =  spreadView.width * spreadView.positionMarker4 - spreadView.shift;
 
442
                spreadView.contentX = Math.min(dragX, maxMovement);
455
443
            }
456
444
            gesturePoints.push(touchX);
457
445
        }
462
450
        onStatusChanged: {
463
451
            previousStatus = currentStatus;
464
452
            currentStatus = status;
465
 
 
466
 
            if (status == DirectionalDragArea.Recognized) {
467
 
                attachedToView = true;
468
 
            }
469
453
        }
470
454
 
471
455
        onDraggingChanged: {
493
477
                // If it was a short one-way movement, do the Alt+Tab switch
494
478
                // no matter if we didn't cross positionMarker1 yet.
495
479
                spreadView.snapTo(1);
496
 
            } else if (!dragging && attachedToView) {
 
480
            } else if (!dragging) {
497
481
                // otherwise snap to the closest snap position we can find
498
482
                // (might be back to start, to app 1 or to spread)
499
483
                spreadView.snap();