From ba6dbcd673d63675ae222f3c538aacb2b25accbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=81=E9=87=87?= Date: Fri, 31 May 2019 09:30:56 +0800 Subject: [PATCH] [improvement] Picker: stop momentum before emit confim event (#3411) --- .../test/__snapshots__/index.spec.js.snap | 12 ++--- .../area/test/__snapshots__/demo.spec.js.snap | 16 +++---- .../test/__snapshots__/index.spec.js.snap | 48 +++++++++---------- .../test/__snapshots__/demo.spec.js.snap | 28 +++++------ packages/picker/PickerColumn.js | 19 +++++--- packages/picker/index.js | 1 + .../test/__snapshots__/demo.spec.js.snap | 16 +++---- .../test/__snapshots__/index.spec.js.snap | 4 +- 8 files changed, 75 insertions(+), 69 deletions(-) diff --git a/packages/address-edit/test/__snapshots__/index.spec.js.snap b/packages/address-edit/test/__snapshots__/index.spec.js.snap index 5dc1d0b1e..2c7277c21 100644 --- a/packages/address-edit/test/__snapshots__/index.spec.js.snap +++ b/packages/address-edit/test/__snapshots__/index.spec.js.snap @@ -40,13 +40,13 @@ exports[`create a AddressEdit 1`] = `
-
    +
      -
        +
          -
            +
              @@ -110,13 +110,13 @@ exports[`create a AddressEdit with props 1`] = `
              -
                +
                  -
                    +
                      -
                        +
                          diff --git a/packages/area/test/__snapshots__/demo.spec.js.snap b/packages/area/test/__snapshots__/demo.spec.js.snap index e548d5bec..617e3c707 100644 --- a/packages/area/test/__snapshots__/demo.spec.js.snap +++ b/packages/area/test/__snapshots__/demo.spec.js.snap @@ -11,7 +11,7 @@ exports[`renders demo correctly 1`] = `
                          -
                            +
                            • 北京市
                            • 天津市
                            • 河北省
                            • @@ -50,12 +50,12 @@ exports[`renders demo correctly 1`] = `
                          -
                            +
                            • 北京市
                          -
                            +
                            • 东城区
                            • 西城区
                            • 朝阳区
                            • @@ -88,7 +88,7 @@ exports[`renders demo correctly 1`] = `
                              -
                                +
                                • 北京市
                                • 天津市
                                • 河北省
                                • @@ -127,7 +127,7 @@ exports[`renders demo correctly 1`] = `
                              -
                                +
                                • 杭州市
                                • 宁波市
                                • 温州市
                                • @@ -142,7 +142,7 @@ exports[`renders demo correctly 1`] = `
                              -
                                +
                                • 鹿城区
                                • 龙湾区
                                • 瓯海区
                                • @@ -171,7 +171,7 @@ exports[`renders demo correctly 1`] = `
                                  -
                                    +
                                    • 北京市
                                    • 天津市
                                    • 河北省
                                    • @@ -210,7 +210,7 @@ exports[`renders demo correctly 1`] = `
                                  -
                                    +
                                    • 北京市
                                  diff --git a/packages/area/test/__snapshots__/index.spec.js.snap b/packages/area/test/__snapshots__/index.spec.js.snap index f47a20f3d..5021bcc1f 100644 --- a/packages/area/test/__snapshots__/index.spec.js.snap +++ b/packages/area/test/__snapshots__/index.spec.js.snap @@ -9,19 +9,19 @@ exports[`change option 1`] = `
                                  -
                                    +
                                    • 北京市
                                    • 天津市
                                  -
                                    +
                                    • 北京市
                                  -
                                    +
                                    • 东城区
                                    • 西城区
                                    @@ -41,19 +41,19 @@ exports[`change option 2`] = `
                                    -
                                      +
                                      • 北京市
                                      • 天津市
                                    -
                                      +
                                      • 天津市
                                    -
                                      +
                                      • 和平区
                                      • 河东区
                                      @@ -73,19 +73,19 @@ exports[`change option 3`] = `
                                      -
                                        +
                                        • 北京市
                                        • 天津市
                                      -
                                        +
                                        • 天津市
                                      -
                                        +
                                        • 和平区
                                        • 河东区
                                        @@ -105,19 +105,19 @@ exports[`reset method 1`] = `
                                        -
                                          +
                                          • 北京市
                                          • 天津市
                                        -
                                          +
                                          • 天津市
                                        -
                                          +
                                          • 蓟县
                                        @@ -136,19 +136,19 @@ exports[`reset method 2`] = `
                                        -
                                          +
                                          • 北京市
                                          • 天津市
                                        -
                                          +
                                          • 北京市
                                        -
                                          +
                                          • 东城区
                                          • 西城区
                                          @@ -168,19 +168,19 @@ exports[`watch areaList & code 1`] = `
                                          -
                                            +
                                            • 北京市
                                            • 天津市
                                          -
                                            +
                                            • 北京市
                                          -
                                            +
                                            • 东城区
                                            • 西城区
                                            @@ -200,19 +200,19 @@ exports[`watch areaList & code 2`] = `
                                            -
                                              +
                                              • 北京市
                                              • 天津市
                                            -
                                              +
                                              • 北京市
                                            -
                                              +
                                              • 东城区
                                              • 西城区
                                              @@ -232,19 +232,19 @@ exports[`watch areaList & code 3`] = `
                                              -
                                                +
                                                • 北京市
                                                • 天津市
                                              -
                                                +
                                                • 北京市
                                              -
                                                +
                                                • 东城区
                                                • 西城区
                                                diff --git a/packages/datetime-picker/test/__snapshots__/demo.spec.js.snap b/packages/datetime-picker/test/__snapshots__/demo.spec.js.snap index 21feaf4f1..c2c21e141 100644 --- a/packages/datetime-picker/test/__snapshots__/demo.spec.js.snap +++ b/packages/datetime-picker/test/__snapshots__/demo.spec.js.snap @@ -11,13 +11,13 @@ exports[`renders demo correctly 1`] = `
                                                -
                                                  +
                                                  • 2018
                                                  • 2019
                                                -
                                                  +
                                                  • 01
                                                  • 02
                                                  • 03
                                                  • @@ -33,7 +33,7 @@ exports[`renders demo correctly 1`] = `
                                                -
                                                  +
                                                  • 01
                                                  • 02
                                                  • 03
                                                  • @@ -68,7 +68,7 @@ exports[`renders demo correctly 1`] = `
                                                -
                                                  +
                                                  • 00
                                                  • 01
                                                  • 02
                                                  • @@ -96,7 +96,7 @@ exports[`renders demo correctly 1`] = `
                                                -
                                                  +
                                                  • 00
                                                  • 01
                                                  • 02
                                                  • @@ -173,7 +173,7 @@ exports[`renders demo correctly 1`] = `
                                                    -
                                                      +
                                                      • 2018
                                                      • 2019
                                                      • 2020
                                                      • @@ -189,7 +189,7 @@ exports[`renders demo correctly 1`] = `
                                                    -
                                                      +
                                                      • 01
                                                      • 02
                                                      • 03
                                                      • @@ -205,7 +205,7 @@ exports[`renders demo correctly 1`] = `
                                                    -
                                                      +
                                                      • 01
                                                      • 02
                                                      • 03
                                                      • @@ -253,7 +253,7 @@ exports[`renders demo correctly 1`] = `
                                                        -
                                                          +
                                                          • 2018年
                                                          • 2019年
                                                          • 2020年
                                                          • @@ -269,7 +269,7 @@ exports[`renders demo correctly 1`] = `
                                                        -
                                                          +
                                                          • 01月
                                                          • 02月
                                                          • 03月
                                                          • @@ -298,7 +298,7 @@ exports[`renders demo correctly 1`] = `
                                                            -
                                                              +
                                                              • 10
                                                              • 11
                                                              • 12
                                                              • @@ -313,7 +313,7 @@ exports[`renders demo correctly 1`] = `
                                                            -
                                                              +
                                                              • 00
                                                              • 01
                                                              • 02
                                                              • @@ -390,7 +390,7 @@ exports[`renders demo correctly 1`] = `
                                                                -
                                                                  +
                                                                  • 00
                                                                  • 01
                                                                  • 02
                                                                  • @@ -418,7 +418,7 @@ exports[`renders demo correctly 1`] = `
                                                                -
                                                                  +
                                                                  • 00
                                                                  • 05
                                                                  • 10
                                                                  • diff --git a/packages/picker/PickerColumn.js b/packages/picker/PickerColumn.js index e2686f7d7..1adf1c153 100644 --- a/packages/picker/PickerColumn.js +++ b/packages/picker/PickerColumn.js @@ -129,13 +129,7 @@ export default sfc({ }, onTransitionEnd() { - this.moving = false; - - if (this.transitionEndTrigger) { - this.duration = DEFAULT_DURATION; - this.transitionEndTrigger(); - this.transitionEndTrigger = null; - } + this.stopMomentum(); }, onClickItem(index) { @@ -213,6 +207,16 @@ export default sfc({ this.duration = MOMENTUM_DURATION; this.setIndex(index, true); }, + + stopMomentum() { + this.moving = false; + this.duration = 0; + + if (this.transitionEndTrigger) { + this.transitionEndTrigger(); + this.transitionEndTrigger = null; + } + } }, render(h) { @@ -223,6 +227,7 @@ export default sfc({ const wrapperStyle = { transform: `translate3d(0, ${this.offset + baseOffset}px, 0)`, transitionDuration: `${this.duration}ms`, + transitionProperty: this.duration ? 'transform' : 'none', lineHeight: `${itemHeight}px` }; diff --git a/packages/picker/index.js b/packages/picker/index.js index 9d9b6a669..59d5a9314 100644 --- a/packages/picker/index.js +++ b/packages/picker/index.js @@ -131,6 +131,7 @@ export default sfc({ }, onConfirm() { + this.children.map(child => child.stopMomentum()); this.emit('confirm'); }, diff --git a/packages/picker/test/__snapshots__/demo.spec.js.snap b/packages/picker/test/__snapshots__/demo.spec.js.snap index 1dbbde6d4..e77596cfe 100644 --- a/packages/picker/test/__snapshots__/demo.spec.js.snap +++ b/packages/picker/test/__snapshots__/demo.spec.js.snap @@ -7,7 +7,7 @@ exports[`renders demo correctly 1`] = `
                                                                    -
                                                                      +
                                                                      • 杭州
                                                                      • 宁波
                                                                      • 温州
                                                                      • @@ -25,7 +25,7 @@ exports[`renders demo correctly 1`] = `
                                                                        -
                                                                          +
                                                                          • 杭州
                                                                          • 宁波
                                                                          • 温州
                                                                          • @@ -48,7 +48,7 @@ exports[`renders demo correctly 1`] = `
                                                                            -
                                                                              +
                                                                              • 杭州
                                                                              • 宁波
                                                                              • 温州
                                                                              • @@ -66,7 +66,7 @@ exports[`renders demo correctly 1`] = `
                                                                                -
                                                                                  +
                                                                                  • 杭州
                                                                                  • 宁波
                                                                                  • 温州
                                                                                  • @@ -82,13 +82,13 @@ exports[`renders demo correctly 1`] = `
                                                                                    -
                                                                                      +
                                                                                      • 浙江
                                                                                      • 福建
                                                                                    -
                                                                                      +
                                                                                      • 杭州
                                                                                      • 宁波
                                                                                      • 温州
                                                                                      • @@ -106,13 +106,13 @@ exports[`renders demo correctly 1`] = `
                                                                                        -
                                                                                          +
                                                                                          • 浙江
                                                                                          • 福建
                                                                                        -
                                                                                          +
                                                                                          • 杭州
                                                                                          • 宁波
                                                                                          • 温州
                                                                                          • diff --git a/packages/picker/test/__snapshots__/index.spec.js.snap b/packages/picker/test/__snapshots__/index.spec.js.snap index f391d82b3..922ce961c 100644 --- a/packages/picker/test/__snapshots__/index.spec.js.snap +++ b/packages/picker/test/__snapshots__/index.spec.js.snap @@ -2,7 +2,7 @@ exports[`column watch default index 1`] = `
                                                                                            -
                                                                                              +
                                                                                              • 1
                                                                                              • 1990
                                                                                              • 1991
                                                                                              • @@ -16,7 +16,7 @@ exports[`column watch default index 1`] = ` exports[`column watch default index 2`] = `
                                                                                                -
                                                                                                  +
                                                                                                  • 1
                                                                                                  • 1990
                                                                                                  • 1991