Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn Physics

Scroll physics tự viết: khiến danh sách dừng đúng chỗ bạn muốn

Cuộn là thao tác người dùng cảm nhận nhiều nhất nhưng mô tả được ít nhất. “Nó rề rà”, “nó không dừng ở chỗ tôi tưởng”, “trên Android nó nảy sai”. Tất cả những lời phàn nàn đó đều trỏ về một lớp nhỏ: ScrollPhysics . Phần lớn lập trình viên Flutter chỉ gặp nó qua ba lớp con có tên sẵn — BouncingScrollPhysics , ClampingScrollPhysics , NeverScrollableScrollPhysics . Bên dưới, đó là một interface gọn với bốn điểm quyết định, và hiểu chúng biến “danh sách dừng ở chỗ kỳ quặc” từ một bí ẩn thành bản sửa hai dòng. Lớp này thật sự quyết định điều gì Phương thức Quyết định applyPhysicsToUserOffset Chuyển động của ngón tay ánh xạ sang offset cuộn ra sao — độ kháng khi overscroll applyBoundaryConditions Từ chối bao nhiêu phần của offset được yêu cầu khi ở mép createBallisticSimulation Chuyện gì xảy ra sau khi nhấc tay: fling, ổn định, snap, hay không gì cả tolerance Khi nào một simulation được coi là kết thúc Cộng thêm hai thuộc tính đáng biết: shouldAcceptUserOffset (...

Scroll physics tự viết: khiến danh sách dừng đúng chỗ bạn muốn

Cuộn là thao tác người dùng cảm nhận nhiều nhất nhưng mô tả được ít nhất. “Nó rề rà”, “nó không dừng ở chỗ tôi tưởng”, “trên Android nó nảy sai”. Tất cả những lời phàn nàn đó đều trỏ về một lớp nhỏ: ScrollPhysics . Phần lớn lập trình viên Flutter chỉ gặp nó qua ba lớp con có tên sẵn — BouncingScrollPhysics , ClampingScrollPhysics , NeverScrollableScrollPhysics . Bên dưới, đó là một interface gọn với bốn điểm quyết định, và hiểu chúng biến “danh sách dừng ở chỗ kỳ quặc” từ một bí ẩn thành bản sửa hai dòng. Lớp này thật sự quyết định điều gì Phương thức Quyết định applyPhysicsToUserOffset Chuyển động của ngón tay ánh xạ sang offset cuộn ra sao — độ kháng khi overscroll applyBoundaryConditions Từ chối bao nhiêu phần của offset được yêu cầu khi ở mép createBallisticSimulation Chuyện gì xảy ra sau khi nhấc tay: fling, ổn định, snap, hay không gì cả tolerance Khi nào một simulation được coi là kết thúc Cộng thêm hai thuộc tính đáng biết: shouldAcceptUserOffset (...

Custom scroll physics: making a list stop where you want it to

Scrolling is the interaction users feel most and describe least. “It feels sluggish”, “it doesn’t stop where I expect”, “it bounces wrong on Android”. Those complaints all point at one small class: ScrollPhysics . Most Flutter developers only ever meet it through the three named subclasses — BouncingScrollPhysics , ClampingScrollPhysics , NeverScrollableScrollPhysics . Underneath, it is a compact interface with four decision points, and understanding those turns “the list stops in a weird place” from a mystery into a two-line fix. What the class actually decides Method Decides applyPhysicsToUserOffset How a finger’s movement maps to scroll offset — resistance when overscrolling applyBoundaryConditions How much of a requested offset to refuse at the edges createBallisticSimulation What happens after the finger lifts: fling, settle, snap, or nothing tolerance When a simulation is considered finished Plus two properties worth knowing: shouldAcceptUserOffset (...

Custom scroll physics: making a list stop where you want it to

Scrolling is the interaction users feel most and describe least. “It feels sluggish”, “it doesn’t stop where I expect”, “it bounces wrong on Android”. Those complaints all point at one small class: ScrollPhysics . Most Flutter developers only ever meet it through the three named subclasses — BouncingScrollPhysics , ClampingScrollPhysics , NeverScrollableScrollPhysics . Underneath, it is a compact interface with four decision points, and understanding those turns “the list stops in a weird place” from a mystery into a two-line fix. What the class actually decides Method Decides applyPhysicsToUserOffset How a finger’s movement maps to scroll offset — resistance when overscrolling applyBoundaryConditions How much of a requested offset to refuse at the edges createBallisticSimulation What happens after the finger lifts: fling, settle, snap, or nothing tolerance When a simulation is considered finished Plus two properties worth knowing: shouldAcceptUserOffset (...