React Native可定制底板組件Magic Sheet使用示例
正文

一個(gè)React Native組件,通過提供一個(gè)強(qiáng)制性的API,可以從應(yīng)用程序的任何地方(甚至在組件之外)調(diào)用,以顯示一個(gè)完全可定制的底部表單,并能夠等待它解決并得到一個(gè)響應(yīng)。
這個(gè)庫依賴于Gorhom的/bottom-sheet 的模態(tài)組件,并接受相同的道具和兒童。
如何使用它
1.安裝并導(dǎo)入
# Yarn $ yarn add react-native-magic-sheet # NPM $ npm i react-native-magic-sheet
2.基本使用方法
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {BottomSheetModalProvider} from '@gorhom/bottom-sheet';
import {MagicSheetPortal} from 'react-native-magic-sheet';
export default function App() {
return (
<OtherProviders>
<GestureHandlerRootView style={{flex: 1}}>
<BottomSheetModalProvider>
<MagicSheetPortal {...defaultProps}/> // <-- On the top of the app component hierarchy
<AppComponents /> // The rest of the app goes here
</BottomSheetModalProvider>
</GestureHandlerRootView>
</OtherProviders>
);
}
import React from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import { magicSheet } from 'react-native-magic-sheet';
const PickerSheet = (someProps) => (
<View>
<TouchableOpacity
onPress={() => {
magicSheet.hide({userName: "Rod", id:1})
}}> // This will hide the sheet, resolve the promise with the passed object
<Text>Return user</Text>
</TouchableOpacity>
</View>
);
const handlePickUser = async () => {
// We can call it with or without props, depending on the requirements.
const result = await magicSheet.show(PickerSheet);
//OR (with props)
const result = await magicSheet.show(() => <PickerSheet {...someProps}/>);
console.log(result)
// will show {userName: "Rod", id:1}, or undefined if sheet is dismissed
};
export const Screen = () => {
return (
<View>
<TouchableOpacity onPress={handlePickUser}>
<Text>Show sheet</Text>
</TouchableOpacity>
</View>
);
};
預(yù)覽

The postFully Customizeable Bottom Sheet Component - Magic Sheetappeared first onReactScript.
以上就是React Native可定制底板組件Magic Sheet使用示例的詳細(xì)內(nèi)容,更多關(guān)于React Native 底板組件的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
React使用TailwindCSS的實(shí)現(xiàn)示例
TailwindCSS是一個(gè)實(shí)用優(yōu)先的CSS框架,本文主要介紹了React使用TailwindCSS的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2023-12-12
React中Portals與錯(cuò)誤邊界處理實(shí)現(xiàn)
本文主要介紹了React中Portals與錯(cuò)誤邊界處理實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-07-07
淺談React + Webpack 構(gòu)建打包優(yōu)化
本篇文章主要介紹了淺談React + Webpack 構(gòu)建打包優(yōu)化,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01
React?Context?變遷及背后實(shí)現(xiàn)原理詳解
這篇文章主要為大家介紹了React?Context?變遷及背后實(shí)現(xiàn)原理示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
react自適應(yīng)布局px轉(zhuǎn)rem實(shí)現(xiàn)示例詳解
這篇文章主要為大家介紹了react自適應(yīng)布局px轉(zhuǎn)rem實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
在?React?Native?中給第三方庫打補(bǔ)丁的過程解析
這篇文章主要介紹了在?React?Native?中給第三方庫打補(bǔ)丁的過程解析,有時(shí)使用了某個(gè)React Native 第三方庫,可是它有些問題,我們不得不修改它的源碼,本文介紹如何修改源碼又不會(huì)意外丟失修改結(jié)果的方法,需要的朋友可以參考下2022-08-08
react+typescript中使用echarts的實(shí)現(xiàn)步驟
本文主要介紹了react+typescript中使用echarts的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08

