react native組件通信方式

1:父組件給子組件通過props

2:   通過回調父組件傳遞一個函數 子組件將執行結果回傳給父組件

3:通過ref方式引用組件調用方法,傳遞參數。

4:通過廣播事件監聽DeviceEventEmitter 註冊監聽事件

5:可以不通過state或者props來更新子view的屬性 

通過setNativeProps直接修改原生屬性 通常用於高頻率更新UI 以提升性能

View

pointerEvents
accessible
accessibilityLabel
accessibilityComponentType
accessibilityLiveRegion
accessibilityTraits
importantForAccessibility
testID
renderToHardwareTextureAndroid
shouldRasterizeIOS
onLayout
onAccessibilityTap
onMagicTap
collapsable
needsOffscreenAlphaCompositing
style

Text
除了包含上面View的所有屬性外還包括:

isHighlighted
numberOfLines
ellipsizeMode
allowFontScaling
selectable
adjustsFontSizeToFit
minimumFontScale

Image
包含View所有支持的屬性, Android 與 IOS 略有不同。Android平臺下,Image組件有children的時候 和 IOS支持的屬性列表一樣,如果Image沒有children,那麼它還包含如下屬性:

src
defaultSource
loadingIndicatorSrc
resizeMode
progressiveRenderingEnabled
fadeDuration
shouldNotifyLoadEvents

6:如果使用redux 通過getstate獲取全局唯一狀態樹


異步與原生通信: react與native異步交互的幾種方式

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章