English
Weex 提供了通过事件触发动作的能力,例如在用户点击组件时执行 JavaScript。
Weex provides the ability to trigger actions through events, such as executing JavaScript when the user clicks on a component.
Below are the common event attributes that can be added to weex components to define event actions.
The principle of native event delivery under Android and iOS is different, only for iOS here.
When a parent view has multiple peer views, iOS will select the highest level View to respond to the event, and the underlying view event will never be responded.
Weex add attribute eventPenetrationEnabled to <div> component. When the value is true(default would be false), the view's children views still respond to the event normally, while the view itself will not respond to the event, but pass the event to the lower level View.
iOS only
Weex add attribute userInteractionEnabled to <div> component. When the value is false(default would be true), neither the view nor its children views respond to the event. The event is passed to the lower layer View.
longpress
If a longpress event is bound to a component, the event will be triggered when user long press on it.
event object
| key | value | Remark |
|---|---|---|
| type | longpress | |
| target | The target component where the event is triggered | |
| timestamp | Timestamp when event is triggered |
Appear
If a appear event is bound to a component inside a scrollable container, the event will be triggered when the component comes to be visible.
event object
| key | value | notes |
|---|---|---|
| type | appear | |
| target | The target component where the event is triggered | |
| timestamp | Timestamp when event is triggered | |
| direction | upor down | The direction in which the scroller is scrolling. |
Disappear
If a disappear event is bound to a component inside a scrollable container, the event will be triggered when the component scrolls out of viewport and disappears from your sight.
event object
| key | value | Remark |
|---|---|---|
| type | disappear | |
| target | The target component where the event is triggered | |
| timestamp | Timestamp when event is triggered | |
| direction | upor down | The direction in which the scroller is scrolling. Could be up or down |