{"id":341,"date":"2022-03-11T13:12:21","date_gmt":"2022-03-11T05:12:21","guid":{"rendered":"https:\/\/blog.iichen.cn\/?p=341"},"modified":"2025-01-23T10:54:30","modified_gmt":"2025-01-23T02:54:30","slug":"android-%e4%ba%8b%e4%bb%b6%e5%88%86%e5%8f%91%e5%92%8c%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/iichen.cn\/?p=341","title":{"rendered":"Android-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406"},"content":{"rendered":"<p><center ><a href=\"https:\/\/www.jianshu.com\/p\/37a80f0d5110\">\u6587\u7ae0\u6e90\u94fe\u63a5<\/a><\/center><\/p>\n<blockquote><p>\n  \u7b80\u5355\u603b\u7ed3\u8bb0\u5f55\n<\/p><\/blockquote>\n<pre><code class=\"language-markdown line-numbers\">GestureBinding:\n    1. handlePointerEvent \u4e8b\u4ef6\u5206\u53d1 -&gt;       _handlePointerEventImmediately\n    2. _handlePointerEventImmediately \u5bf9down\/up,cancel\u7b49\u4e8b\u4ef6\u8fdb\u884c\u5904\u7406\n        2.1 pointerDown\u4e8b\u4ef6\uff0c\u4f1a\u8fdb\u884chittest\u547d\u4e2d\u6d4b\u8bd5 -&gt; renderView.hitTest -&gt; renderBox\u7684hitTest\n            2.1.1 renderView\u662fRenderObject\u6811\u7684\u6839\uff0c\u4ece\u8fd9\u91cc\u904d\u5386\u6574\u9897RenderTree\uff0c\u6267\u884chitTest \u5373 renderBox\u7684hitTest\n            2.1.2 renderbox\u8fd9\u91cc\u6709\u4e2a\u5173\u952e\u7684\u4f4d\u7f6e\uff1a hitTestChild || hitTestSelf\uff0c\u610f\u5473\u7740child\u5148\u88ab\u547d\u4e2d\u6d4b\u8bd5\u5c31\u76f4\u63a5\u8fd4\u56de\u7ed3\u675f\n        2.2 hitTest\u8fd4\u56deTrue\u540e\uff0c\u5c06\u5176\u6dfb\u52a0\u5230hitTestResult\u5185\uff0c\u4ee5\u4f9b\u540e\u7eed\u7684\u4e8b\u4ef6\u5206\u53d1\u5904\u7406  \n            entry.target.handleEvent() =&gt; RenderObject \u9ed8\u8ba4\u6709\u5b9e\u73b0HitTestTarget\uff0c\u4f46\u662f\u4e2a\u7a7a\u5b9e\u73b0\uff0c\u53ea\u6709\u9700\u8981\u5904\u7406\u4e8b\u4ef6\u7684render\u624d\u4f1a\u5b9e\u73b0\n\n    3. dispatchEvent\n        3.1 \u6ca1\u6709\u547d\u4e2d\u7684  ==\u300b pointerRouter.route(event); \u8fd9\u91cc\u5728GestureDetector\u90e8\u5206\u67e5\u770b\n        3.2 for (final HitTestEntry entry in hitTestResult.path) \u904d\u5386\u8fdb\u884c \u5904\u7406\u4e8b\u4ef6\n\n\n    4. \u603b\u7ed3\n        \u5f53\u8bbe\u5907\u89e6\u53d1point\u4e8b\u4ef6\u65f6\uff0c\u53c2\u4e0e\u5206\u53d1\u7684binding\u6709RenderBinding\u548cGestureBinding,RenderView\u662fRenderTree\u5206\u53d1\u7684\u603b\u5165\u53e3\n        \u5f53\u4e8b\u4ef6\u4e3apoint down\u65f6\uff0c\u5f00\u59cb\u6267\u884chitTest()\u6d4b\u8bd5\uff0c\u628a\u7b26\u5408\u6761\u4ef6\u7684RenderObject\u52a0\u5165\u5230hitTestResult\u4e2d\n        \u5982\u679c\u662f\u5176\u4ed6\u4e8b\u4ef6\uff0c\u5c31\u6839\u636epoint id \u53d6\u51fa\u4e4b\u524d\u7684hitTestResult\u5e76\u5206\u53d1\n        \u6700\u540e\u5c31\u662f\u904d\u5386hitTestResult\uff0c\u6267\u884c entry.target.handleEvent();\n\n\nGestureDetector -&gt; RawGestureDetectorState -&gt; Listener\n\n\n\u4e8b\u4ef6\u51b2\u7a81 - \u624b\u52bf\u7ade\u6280\u573a\n    1. handleEvent\u5185\uff0c\u4e3b\u8981 \u56db\u4e2a\u65b9\u6cd5\n        1.1 \u5206\u53d1event pointerRouter.route(event);\n        1.2 pointDownEvent =&gt; gestureArena.close(event.pointer);\n        1.3 PointerUpEvent =&gt; gestureArena.sweep(event.pointer);\n        1.4 PointerSignalEvent =&gt; pointerSignalResolver.resolve(event);\n    2. close\u65b9\u6cd5 - down\u4e8b\u4ef6\u505c\u6b62\u65b0\u7684\u6210\u5458\u8fdb\u884c\u7ade\u6280\u573a\n        2.1 \u6709\u4e2a\u5173\u6ce8\u70b9\uff1aeagerWinner\u6fc0\u8fdb\u7684\u7ade\u4e89\u8005 \u76f4\u63a5 acceptGesture \n    3. sweep\u65b9\u6cd5 -    \n\nListener\u5185\u5bf9\u76f8\u5173HitTestBehavior\u8bbe\u7f6e\n    # \u5982\u679cBehavior\u662fopaque\uff0c\u4e14\u5b50\u7c7b\u6ca1\u6709\u91cd\u5199hitTestSelf\uff0c\u5219\u81ea\u5df1\u52a0\u5165\u5230\u4e8b\u4ef6\u6d88\u8d39\u7684\u884c\u5217\n    # behavior == HitTestBehavior.translucent \u540c\u4e0a\n\n    # _handlePointerDown\u65b9\u6cd5 -&gt; -&gt; -&gt; addAllowedPointer -&gt; startTrackingPointer\n        \u5373GestureDetector\u5185\u4f7f\u7528\u5404\u79cd\u624b\u52bf\u8bc6\u522b\u65f6 GestureDetector\u4f1a\u5c06\u5176\u6dfb\u52a0\u5230\u624b\u52bf\u7ade\u6280\u573a\n        GestureBinding.instance.pointerRouter.addRoute(pointer, handleEvent, transform); event\u5206\u53d1\n\n\n\nContainer\u5176\u5b9e\u662f\u4e2aStateLessWidget\uff0c\u5b83\u672c\u8eab\u5e76\u6ca1\u6709RenderObject\u5bf9\u5e94\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u662f\u4e2a\u914d\u7f6e\u9879\uff0c\u771f\u5b9e\u6e32\u67d3\u7684render\u662f\u5176\u4ed6\u914d\u7f6e\u5f15\u8fdb\u7684\uff0c\u6bd4\u5982color\u5bf9\u5e94\u7684ColoredBox\n\u6240\u4ee5Container\u8bbe\u7f6e\u4efb\u610f\u80cc\u666f\u8272\uff0c\u53ef\u4ee5\u54cd\u5e94\u70b9\u51fb\u4e8b\u4ef6\n\n\nPointerRouter\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6e90\u94fe\u63a5 \u7b80\u5355\u603b\u7ed3\u8bb0\u5f55 GestureBinding: 1. handlePointerEvent \u4e8b\u4ef6\u5206\u53d1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,8],"tags":[],"class_list":["post-341","post","type-post","status-publish","format-standard","hentry","category-android","category-8"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406 - IIchen<\/title>\n<meta name=\"description\" content=\"Flutter-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/iichen.cn\/?p=341\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406 - IIchen\" \/>\n<meta property=\"og:description\" content=\"Flutter-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406\" \/>\n<meta property=\"og:url\" content=\"https:\/\/iichen.cn\/?p=341\" \/>\n<meta property=\"og:site_name\" content=\"IIchen\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-11T05:12:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-23T02:54:30+00:00\" \/>\n<meta name=\"author\" content=\"iichen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"iichen\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/iichen.cn\/?p=341#article\",\"isPartOf\":{\"@id\":\"https:\/\/iichen.cn\/?p=341\"},\"author\":{\"name\":\"iichen\",\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c\"},\"headline\":\"Android-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406\",\"datePublished\":\"2022-03-11T05:12:21+00:00\",\"dateModified\":\"2025-01-23T02:54:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/iichen.cn\/?p=341\"},\"wordCount\":1,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c\"},\"articleSection\":[\"Android\",\"\u7b14\u8bb0\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/iichen.cn\/?p=341#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/iichen.cn\/?p=341\",\"url\":\"https:\/\/iichen.cn\/?p=341\",\"name\":\"Android-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406 - IIchen\",\"isPartOf\":{\"@id\":\"https:\/\/iichen.cn\/#website\"},\"datePublished\":\"2022-03-11T05:12:21+00:00\",\"dateModified\":\"2025-01-23T02:54:30+00:00\",\"description\":\"Flutter-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406\",\"breadcrumb\":{\"@id\":\"https:\/\/iichen.cn\/?p=341#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/iichen.cn\/?p=341\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/iichen.cn\/?p=341#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/iichen.cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/iichen.cn\/#website\",\"url\":\"https:\/\/iichen.cn\/\",\"name\":\"IIchen\",\"description\":\"Just do it!\",\"publisher\":{\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/iichen.cn\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c\",\"name\":\"iichen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/iichen.cn\/wp-content\/uploads\/2025\/01\/avatar.jpg\",\"contentUrl\":\"https:\/\/iichen.cn\/wp-content\/uploads\/2025\/01\/avatar.jpg\",\"width\":940,\"height\":940,\"caption\":\"iichen\"},\"logo\":{\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/www.iichen.cn\"],\"url\":\"https:\/\/iichen.cn\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406 - IIchen","description":"Flutter-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/iichen.cn\/?p=341","og_locale":"zh_CN","og_type":"article","og_title":"Android-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406 - IIchen","og_description":"Flutter-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406","og_url":"https:\/\/iichen.cn\/?p=341","og_site_name":"IIchen","article_published_time":"2022-03-11T05:12:21+00:00","article_modified_time":"2025-01-23T02:54:30+00:00","author":"iichen","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"iichen","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/iichen.cn\/?p=341#article","isPartOf":{"@id":"https:\/\/iichen.cn\/?p=341"},"author":{"name":"iichen","@id":"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c"},"headline":"Android-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406","datePublished":"2022-03-11T05:12:21+00:00","dateModified":"2025-01-23T02:54:30+00:00","mainEntityOfPage":{"@id":"https:\/\/iichen.cn\/?p=341"},"wordCount":1,"commentCount":0,"publisher":{"@id":"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c"},"articleSection":["Android","\u7b14\u8bb0"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/iichen.cn\/?p=341#respond"]}]},{"@type":"WebPage","@id":"https:\/\/iichen.cn\/?p=341","url":"https:\/\/iichen.cn\/?p=341","name":"Android-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406 - IIchen","isPartOf":{"@id":"https:\/\/iichen.cn\/#website"},"datePublished":"2022-03-11T05:12:21+00:00","dateModified":"2025-01-23T02:54:30+00:00","description":"Flutter-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406","breadcrumb":{"@id":"https:\/\/iichen.cn\/?p=341#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/iichen.cn\/?p=341"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/iichen.cn\/?p=341#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/iichen.cn\/"},{"@type":"ListItem","position":2,"name":"Android-\u4e8b\u4ef6\u5206\u53d1\u548c\u5904\u7406"}]},{"@type":"WebSite","@id":"https:\/\/iichen.cn\/#website","url":"https:\/\/iichen.cn\/","name":"IIchen","description":"Just do it!","publisher":{"@id":"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/iichen.cn\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c","name":"iichen","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/iichen.cn\/#\/schema\/person\/image\/","url":"https:\/\/iichen.cn\/wp-content\/uploads\/2025\/01\/avatar.jpg","contentUrl":"https:\/\/iichen.cn\/wp-content\/uploads\/2025\/01\/avatar.jpg","width":940,"height":940,"caption":"iichen"},"logo":{"@id":"https:\/\/iichen.cn\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/www.iichen.cn"],"url":"https:\/\/iichen.cn\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/posts\/341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iichen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=341"}],"version-history":[{"count":1,"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/posts\/341\/revisions"}],"predecessor-version":[{"id":737,"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/posts\/341\/revisions\/737"}],"wp:attachment":[{"href":"https:\/\/iichen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iichen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iichen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}