llms-full.txt 247 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922
  1. # Ant Design Mobile RN Component Documentation
  2. Aggregated content from all component docs.
  3. > 47 components
  4. ## Accordion
  5. Source: https://rn.mobile.ant.design/components/accordion.md
  6. # Accordion
  7. > This package has been deprecated in `5.2.1`, recommend [components/Collapse](/components/collapse)
  8. You can collapse / expand the content area.
  9. ### Rules
  10. - Group and hide complex areas.
  11. - Typically, only a single content area is allowed to expand at a time; in special cases, multiple content areas can be expanded at the same time.
  12. ## Examples
  13. ```tsx
  14. import { Accordion, List } from '@ant-design/react-native'
  15. import React from 'react'
  16. import { View } from 'react-native'
  17. export default class AccordionExmple extends React.Component<any, any> {
  18. state = {
  19. activeSections: [2, 0],
  20. }
  21. onChange = (activeSections: number[]) => {
  22. this.setState({ activeSections })
  23. }
  24. render() {
  25. return (
  26. <View style={{ marginTop: 80, marginBottom: 10 }}>
  27. <Accordion
  28. onChange={this.onChange}
  29. activeSections={this.state.activeSections}>
  30. <Accordion.Panel header="Title 1">
  31. <List>
  32. <List.Item>Content 1</List.Item>
  33. <List.Item>Content 2</List.Item>
  34. <List.Item>Content 3</List.Item>
  35. </List>
  36. </Accordion.Panel>
  37. <Accordion.Panel header="Title 2">
  38. this is panel content2 or other
  39. </Accordion.Panel>
  40. <Accordion.Panel header="Title 3">
  41. Text text text text text text text text text text text text text
  42. text text
  43. </Accordion.Panel>
  44. </Accordion>
  45. </View>
  46. )
  47. }
  48. }
  49. ```
  50. ## API
  51. ### Accordion
  52. | Properties | Descrition | Type | Default |
  53. | ----------------- | ------------------------------------------------------------------------------------------------ | ------------------------- | ------- |
  54. | onChange(indexes) | A function that is called when the currently active section(s) are updated. | (indexes: number[])=>void | - |
  55. | activeSections | Control which indices in the `sections` array are currently open. If empty, closes all sections. | number[] | [] |
  56. Read more https://github.com/oblador/react-native-collapsible#properties-1
  57. ### Accordion.Panel
  58. | Properties | Descrition | Type | Default |
  59. | ---------- | ----------------------- | ----------------------- | ------- |
  60. | key | corresponding activeKey | String | - |
  61. | header | header content of Panel | React.Element or String | - |
  62. Note: Currently does not support nested use for RN.
  63. ---
  64. ## ActionSheet
  65. Source: https://rn.mobile.ant.design/components/action-sheet.md
  66. # ActionSheet
  67. The modal box pops up from the bottom, providing more than two actions related to the current scene, and also support provide the title and description. Built-in fixed display style, does not support particularly flexible changes.
  68. ### Rules
  69. - Provide a clear exit button.
  70. - Can highlight the destructive operation, e.g. "delete" use red text.
  71. - Do not place too much content to avoid vertical roll of the panel.
  72. ## Examples
  73. ```tsx
  74. import { ActionSheet, Button, Provider } from '@ant-design/react-native'
  75. import React from 'react'
  76. import { Platform, Text, View } from 'react-native'
  77. export default class Test extends React.Component<any, any> {
  78. constructor(props: any) {
  79. super(props)
  80. this.state = {
  81. clicked: 'none',
  82. text: '',
  83. }
  84. }
  85. render() {
  86. return (
  87. <Provider>
  88. <View style={{ marginTop: 30 }}>
  89. <View style={[{ padding: 8 }]}>
  90. <Button onPress={this.showActionSheet}>showActionSheet</Button>
  91. </View>
  92. <Text style={[{ padding: 8 }]}>
  93. clicked button: {this.state.clicked}
  94. </Text>
  95. <View style={[{ padding: 8 }]}>
  96. <Button onPress={this.showShareActionSheet}>
  97. showShareActionSheet
  98. </Button>
  99. </View>
  100. <Text style={[{ padding: 8 }]}>{this.state.text}</Text>
  101. </View>
  102. </Provider>
  103. )
  104. }
  105. showActionSheet = () => {
  106. const BUTTONS = [
  107. 'Operation1',
  108. 'Operation2',
  109. 'Operation3',
  110. 'Delete',
  111. 'Cancel',
  112. ]
  113. ActionSheet.showActionSheetWithOptions(
  114. {
  115. title: 'Title',
  116. message: 'Description',
  117. options: BUTTONS,
  118. cancelButtonIndex: 4,
  119. destructiveButtonIndex: 3,
  120. },
  121. (buttonIndex: any) => {
  122. this.setState({ clicked: BUTTONS[buttonIndex] })
  123. },
  124. )
  125. }
  126. showShareActionSheet = () => {
  127. const opts: any = {
  128. message: 'Message to go with the shared url',
  129. title: 'Share Actionsheet',
  130. }
  131. if (Platform.OS === 'ios') {
  132. opts.url = 'https://www.alipay.com/'
  133. opts.tintColor = '#ff0000'
  134. opts.excludedActivityTypes = ['com.apple.UIKit.activity.PostToTwitter']
  135. }
  136. ActionSheet.showShareActionSheetWithOptions(
  137. opts,
  138. (error: any) => alert(error),
  139. (success: any, method: any) => {
  140. let text
  141. if (success) {
  142. text = `Shared with ${method}`
  143. } else {
  144. text = 'Did not share'
  145. }
  146. this.setState({ text })
  147. },
  148. )
  149. }
  150. }
  151. export const title = 'ActionSheet'
  152. export const description = 'ActionSheet example'
  153. ```
  154. ## API
  155. ### ActionSheet.showActionSheetWithOptions(options, callback)
  156. Properties | Descrition | Type | Default
  157. ----|-----|------|------
  158. | options | ActionSheet's options | Object | - |
  159. | callback | Callback for selected item | (index:number):void | - |
  160. Display a action sheet. The `options` object must contain one or more of:
  161. Properties | Descrition | Type | Default
  162. ----|-----|------|------
  163. | options | a list of button titles (required) | Array or String | - |
  164. | cancelButtonIndex | index of cancel button in `options` | Number | - |
  165. | destructiveButtonIndex | index of destructive button in `options` | Number | - |
  166. | title | a title to show above the action sheet | String | - |
  167. | message | a message to show below the title | String or React.element | - |
  168. ### ActionSheet.showShareActionSheetWithOptions(options, failureCallback?, successCallback?)
  169. `React-Native Only, react-native@version >= 0.39`
  170. Properties | Descrition | Type | Default
  171. ----|-----|------|------
  172. | options | ShareActionSheet's options | Object | - |
  173. | failureCallback | Callback for share failed(`iOS Only`, See [react-native/share](https://github.com/facebook/react-native/blob/master/Libraries/Share/Share.js#L80) ) | (error):void | - |
  174. | successCallback | Callback for share successed(`iOS Only`, See [react-native/share](https://github.com/facebook/react-native/blob/master/Libraries/Share/Share.js#L80) ) | (completed:Boolean, activityType?:String):void | - |
  175. Display a shareable action sheet. The `options` object must contain one or more of:
  176. Properties | Descrition | Type | Default
  177. ----|-----|------|------
  178. | message | a message to share | String | - |
  179. | title | title of the message | String | - |
  180. | url | an URL to share `iOS Only` | String | - |
  181. | excludedActivityTypes | the activities to exclude from the ShareActionSheet `iOS Only` | Array | - |
  182. ### ActionSheet.close()
  183. Close the action sheet.`Android Only`
  184. ---
  185. ## ActivityIndicator
  186. Source: https://rn.mobile.ant.design/components/activity-indicator.md
  187. # ActivityIndicator
  188. `ActivityIndicator` indicates that a task is currently in progress.
  189. ### Rules
  190. - Don't stop activity indicator if the task is not completed.
  191. - By providing meaningful texts under certain circumstances can help user understand which task is in progress. eg: uploading photos.
  192. - If you know the user's waiting time, you can use `Progress` instead.
  193. ## Examples
  194. ```tsx
  195. import { ActivityIndicator, Button, Flex, WhiteSpace, WingBlank } from '@ant-design/react-native'
  196. import React from 'react'
  197. import { StyleSheet, Text, View } from 'react-native'
  198. export default class ActivityIndicatorExample extends React.Component<
  199. any,
  200. any
  201. > {
  202. closeTimer: any
  203. constructor(props: any) {
  204. super(props)
  205. this.state = {
  206. animating: false,
  207. }
  208. this.loadingToast = this.loadingToast.bind(this)
  209. }
  210. componentWillUnmount() {
  211. clearTimeout(this.closeTimer)
  212. }
  213. loadingToast() {
  214. this.setState({ animating: !this.state.animating })
  215. this.closeTimer = setTimeout(() => {
  216. this.setState({ animating: !this.state.animating })
  217. }, 2000)
  218. }
  219. render() {
  220. return (
  221. <View style={[styles.demo]}>
  222. <WingBlank>
  223. <Flex>
  224. <Flex.Item>
  225. <Text>Icon without text</Text>
  226. </Flex.Item>
  227. <Flex.Item>
  228. <ActivityIndicator />
  229. </Flex.Item>
  230. </Flex>
  231. </WingBlank>
  232. <WhiteSpace size="xl" style={{ backgroundColor: '#fff' }} />
  233. <WingBlank>
  234. <Flex>
  235. <Flex.Item>
  236. <Text>Icon with text</Text>
  237. </Flex.Item>
  238. <Flex.Item>
  239. <ActivityIndicator text="Loading..." />
  240. </Flex.Item>
  241. </Flex>
  242. </WingBlank>
  243. <WhiteSpace size="xl" style={{ backgroundColor: '#fff' }} />
  244. <WingBlank>
  245. <Flex>
  246. <Flex.Item>
  247. <Text>Dark Background</Text>
  248. </Flex.Item>
  249. <Flex.Item>
  250. <View style={[styles.darkBg]}>
  251. <ActivityIndicator color="#fff" />
  252. </View>
  253. </Flex.Item>
  254. </Flex>
  255. </WingBlank>
  256. <WhiteSpace size="xl" style={{ backgroundColor: '#fff' }} />
  257. <WingBlank>
  258. <Flex>
  259. <Flex.Item>
  260. <Text>Large Size</Text>
  261. </Flex.Item>
  262. <Flex.Item>
  263. <ActivityIndicator size="large" />
  264. </Flex.Item>
  265. </Flex>
  266. </WingBlank>
  267. <WhiteSpace size="xl" style={{ backgroundColor: '#fff' }} />
  268. <WingBlank>
  269. <Button onPress={this.loadingToast}>Click to show Toast</Button>
  270. </WingBlank>
  271. <ActivityIndicator
  272. animating={this.state.animating}
  273. toast
  274. size="large"
  275. text="Loading..."
  276. />
  277. </View>
  278. )
  279. }
  280. }
  281. const styles = StyleSheet.create({
  282. demo: {
  283. marginTop: 20,
  284. },
  285. darkBg: {
  286. alignItems: 'center',
  287. justifyContent: 'center',
  288. width: 89,
  289. height: 89,
  290. backgroundColor: '#2B2F42',
  291. },
  292. gray: {
  293. backgroundColor: '#CCC',
  294. },
  295. horizontal: {
  296. flexDirection: 'row',
  297. justifyContent: 'space-around',
  298. padding: 8,
  299. },
  300. })
  301. ```
  302. ## API
  303. ```jsx
  304. <ActivityIndicator />
  305. <ActivityIndicator color="white" />
  306. <ActivityIndicator size="large" />
  307. <ActivityIndicator text="loading" />
  308. <ActivityIndicator toast />
  309. <ActivityIndicator toast text="loading" />
  310. ```
  311. ### ActivityIndicator
  312. Properties | Descrition | Type | Default
  313. -----------|------------|------|--------
  314. | animating | Whether to show the indicator (true, the default) or hide it (false). | boolean | true |
  315. | size | Size of the indicator (`small`/`large` or number [android only]) | string\|number | small |
  316. | toast | Whether to use toast style | boolean | false |
  317. | text | loading text behind the indicator | string | - |
  318. | color | The foreground color of the spinner (default is gray). | string | gray |
  319. ---
  320. ## Badge
  321. Source: https://rn.mobile.ant.design/components/badge.md
  322. # Badge
  323. The red dot at corner for notification and getting user attention.
  324. ### When to use
  325. - Use plain dot badge when user just need to know there is something new, eg: one-to-one new messages.
  326. - Use numberic badge when user need to know specific number of notifications, eg: new messages from a group.
  327. ## Examples
  328. ```tsx
  329. import { Badge, WhiteSpace } from '@ant-design/react-native'
  330. import React from 'react'
  331. import { ScrollView, View } from 'react-native'
  332. export default class BasicTagExample extends React.Component<any, any> {
  333. render() {
  334. return (
  335. <ScrollView
  336. style={{ flex: 1 }}
  337. automaticallyAdjustContentInsets={false}
  338. showsHorizontalScrollIndicator={false}
  339. showsVerticalScrollIndicator={false}>
  340. <View style={{ padding: 20 }}>
  341. <Badge text={9}>
  342. <View
  343. style={{
  344. width: 52,
  345. height: 52,
  346. backgroundColor: 'rgba(255, 140, 101, 0.15)',
  347. }}
  348. />
  349. </Badge>
  350. <WhiteSpace size="lg" />
  351. <Badge text={109} overflowCount={100}>
  352. <View
  353. style={{
  354. width: 52,
  355. height: 52,
  356. backgroundColor: 'rgba(255, 140, 101, 0.15)',
  357. }}
  358. />
  359. </Badge>
  360. <WhiteSpace size="lg" />
  361. <Badge text={109}>
  362. <View
  363. style={{
  364. width: 52,
  365. height: 52,
  366. backgroundColor: 'rgba(255, 140, 101, 0.15)',
  367. }}
  368. />
  369. </Badge>
  370. <WhiteSpace size="lg" />
  371. <Badge text="new">
  372. <View
  373. style={{
  374. width: 52,
  375. height: 52,
  376. backgroundColor: 'rgba(255, 140, 101, 0.15)',
  377. }}
  378. />
  379. </Badge>
  380. <WhiteSpace size="lg" />
  381. <Badge text={109} dot>
  382. <View
  383. style={{
  384. width: 52,
  385. height: 52,
  386. backgroundColor: 'rgba(255, 140, 101, 0.15)',
  387. }}
  388. />
  389. </Badge>
  390. <WhiteSpace size="lg" />
  391. <Badge text={33} corner>
  392. <View
  393. style={{
  394. width: 52,
  395. height: 52,
  396. backgroundColor: 'rgba(255, 140, 101, 0.15)',
  397. }}
  398. />
  399. </Badge>
  400. </View>
  401. </ScrollView>
  402. )
  403. }
  404. }
  405. ```
  406. ## API
  407. Properties | Descrition | Type | Default
  408. -----------|------------|------|--------
  409. size | size of badge, optional: `large` `small` | string | `small`
  410. text | text or number inside badge | string\|number | -
  411. corner | whether is badge at corner position | boolean | `false`
  412. dot | show badge as a red dot | boolean | `false`
  413. overflowCount | max count to show | number | `99`
  414. ---
  415. ## Button
  416. Source: https://rn.mobile.ant.design/components/button.md
  417. # Button
  418. To trigger an operation.
  419. ## Examples
  420. ```tsx
  421. import { Button, Icon, WhiteSpace, WingBlank } from '@ant-design/react-native'
  422. import React from 'react'
  423. export default () => (
  424. <WingBlank>
  425. <WhiteSpace />
  426. <Button>default</Button>
  427. <WhiteSpace />
  428. <Button disabled>default disabled</Button>
  429. <WhiteSpace />
  430. <Button type="primary">primary</Button>
  431. <WhiteSpace />
  432. <Button type="primary" disabled>
  433. primary disabled
  434. </Button>
  435. <WhiteSpace />
  436. <Button type="warning">warning</Button>
  437. <WhiteSpace />
  438. <Button type="warning" disabled>
  439. warning disabled
  440. </Button>
  441. <WhiteSpace />
  442. <Button loading>loading button</Button>
  443. <Button activeStyle={false}>No click feedback</Button>
  444. <WhiteSpace />
  445. <Button underlayColor={'blue'}>Custom Underlay</Button>
  446. <Button activeStyle={{ backgroundColor: 'red' }}>
  447. custom feedback style
  448. </Button>
  449. <WhiteSpace />
  450. <Button
  451. styles={{
  452. rawText: { color: 'darkgray' },
  453. }}
  454. style={{
  455. backgroundColor: 'red',
  456. }}>
  457. custon background and text color
  458. </Button>
  459. <WingBlank
  460. style={{
  461. marginTop: 20,
  462. flexDirection: 'row',
  463. justifyContent: 'space-between',
  464. alignItems: 'center',
  465. }}>
  466. <Button type="ghost">ghost</Button>
  467. <Button type="ghost" disabled>
  468. ghost disabled
  469. </Button>
  470. <Button type="ghost" size="small">
  471. ghost
  472. </Button>
  473. </WingBlank>
  474. <WhiteSpace />
  475. <Button type="primary">
  476. <Icon name="login" />
  477. </Button>
  478. </WingBlank>
  479. )
  480. ```
  481. ## API
  482. Properties | Descrition | Type | Default
  483. -----------|------------|------|--------
  484. | type | can be set to `primary`/`ghost`/`warning` or omitted | string | - |
  485. | size | can be set to `large`、`small` or omitted | string | `large`|
  486. | activeStyle | the feedback's custom style (set to false to disable click feedback) | {}/false | {} |
  487. | activeClassName | the feedback's custom class name | string | |
  488. | disabled | set disabled | boolean | false |
  489. | onPress | set the handler to handle `click` event | (e: Object): void | - |
  490. | style | custom style | Object | - |
  491. | styles | Semantic DOM style | [ButtonStyles](#buttonStyles-interface) | - |
  492. | onPressIn | same as RN Pressable onPressIn | (e: Object): void | - |
  493. | onPressOut | same as RN Pressable onPressOut | (e: Object): void | - |
  494. | onShowUnderlay | same as RN Pressable onPressIn but only triggered if `activeStyle` is not false | (e: Object): void | - |
  495. | onHideUnderlay | same as RN Pressable onPressOut but only triggered if `activeStyle` is not false | (e: Object): void | - |
  496. ### ButtonStyles interface
  497. ```typescript
  498. interface ButtonStyles {
  499. container: ViewStyle
  500. defaultHighlight: ViewStyle
  501. primaryHighlight: ViewStyle
  502. ghostHighlight: ViewStyle
  503. warningHighlight: ViewStyle
  504. wrapperStyle: ViewStyle
  505. underlayStyle: ViewStyle
  506. largeRaw: ViewStyle
  507. largeUnderlayContainerRaw: ViewStyle
  508. smallRaw: ViewStyle
  509. smallUnderlayContainerRaw: ViewStyle
  510. defaultRaw: ViewStyle
  511. defaultUnderlayContainerRaw: ViewStyle
  512. primaryRaw: ViewStyle
  513. primaryUnderlayContainerRaw: ViewStyle
  514. ghostRaw: ViewStyle
  515. ghostUnderlayContainerRaw: ViewStyle
  516. warningRaw: ViewStyle
  517. warningUnderlayContainerRaw: ViewStyle
  518. defaultDisabledRaw: ViewStyle
  519. primaryDisabledRaw: ViewStyle
  520. ghostDisabledRaw: ViewStyle
  521. warningDisabledRaw: ViewStyle
  522. defaultHighlightText: TextStyle
  523. primaryHighlightText: TextStyle
  524. ghostHighlightText: TextStyle
  525. warningHighlightText: TextStyle
  526. rawText: TextStyle
  527. largeRawText: TextStyle
  528. smallRawText: TextStyle
  529. defaultRawText: TextStyle
  530. primaryRawText: TextStyle
  531. ghostRawText: TextStyle
  532. warningRawText: TextStyle
  533. defaultDisabledRawText: TextStyle
  534. primaryDisabledRawText: TextStyle
  535. ghostDisabledRawText: TextStyle
  536. warningDisabledRawText: TextStyle
  537. indicator: ViewStyle
  538. }
  539. ```
  540. ---
  541. ## Card
  542. Source: https://rn.mobile.ant.design/components/card.md
  543. # Card
  544. Card can be used to organize information and operations, usually also as an entry for detailed information.
  545. ### Rules
  546. - The shape is rectangular.
  547. - The content can consist of multiple elements of varying type, eg: images, texts, buttons, etc.
  548. ## Examples
  549. ```tsx
  550. import { Card, WhiteSpace, WingBlank } from '@ant-design/react-native'
  551. import React from 'react'
  552. import { Text, View } from 'react-native'
  553. export default class BasicCardExample extends React.Component<any, any> {
  554. render() {
  555. return (
  556. <View style={{ paddingTop: 30 }}>
  557. <WingBlank size="lg">
  558. <Card>
  559. <Card.Header
  560. title="This is title"
  561. thumbStyle={{ width: 30, height: 30 }}
  562. thumb="https://gw.alipayobjects.com/zos/rmsportal/MRhHctKOineMbKAZslML.jpg"
  563. extra="this is extra"
  564. />
  565. <Card.Body>
  566. <View style={{ height: 42 }}>
  567. <Text style={{ marginLeft: 16 }}>Card Content</Text>
  568. </View>
  569. </Card.Body>
  570. <Card.Footer
  571. content="footer content"
  572. extra="footer extra content"
  573. />
  574. </Card>
  575. </WingBlank>
  576. <WhiteSpace size="lg" />
  577. <Card full>
  578. <Card.Header
  579. title="Full Column"
  580. thumbStyle={{ width: 30, height: 30 }}
  581. thumb="https://gw.alipayobjects.com/zos/rmsportal/MRhHctKOineMbKAZslML.jpg"
  582. extra="this is extra"
  583. />
  584. <Card.Body>
  585. <View style={{ height: 42 }}>
  586. <Text style={{ marginLeft: 16 }}>Card Content</Text>
  587. </View>
  588. </Card.Body>
  589. <Card.Footer content="footer content" extra="footer extra content" />
  590. </Card>
  591. </View>
  592. )
  593. }
  594. }
  595. ```
  596. ## API
  597. ### Card
  598. Properties | Descrition | Type | Default
  599. -----------|------------|------|--------
  600. | full | whether is full column | boolean | `false` |
  601. ### Card.Header
  602. Properties | Descrition | Type | Default
  603. -----------|------------|------|--------
  604. |title| title for `Card.Header` | React.Element、String | |
  605. |thumb| thumb to render in the left of `Card.Header` | String、React.Element | |
  606. |thumbStyle| style of thumb | Object | {} |
  607. |extra| extra content to render in the right of `Card.Header` | React.Element、String | |
  608. ### Card.Body
  609. Properties | Descrition | Type | Default
  610. -----------|------------|------|--------
  611. | | | | |
  612. ### Card.Footer
  613. Properties | Descrition | Type | Default
  614. -----------|------------|------|--------
  615. |content| content of `Card.Footer` | React.Element、String | |
  616. |extra| extra content of `Card.Footer` | React.Element、String | |
  617. ---
  618. ## Carousel
  619. Source: https://rn.mobile.ant.design/components/carousel.md
  620. # Carousel
  621. ## Examples
  622. ```tsx
  623. import { Button, Carousel } from '@ant-design/react-native'
  624. import React from 'react'
  625. import {
  626. ScrollView,
  627. StyleSheet,
  628. Text,
  629. TextStyle,
  630. View,
  631. ViewStyle,
  632. } from 'react-native'
  633. export default class BasicCarouselExample extends React.Component<any, any> {
  634. carousel: null | Carousel
  635. constructor(props: any) {
  636. super(props)
  637. this.state = {
  638. selectedIndex: 2,
  639. autoplay: true,
  640. }
  641. }
  642. onHorizontalSelectedIndexChange = (index: number) => {
  643. /* tslint:disable: no-console */
  644. console.log('horizontal change to', index)
  645. this.setState({ selectedIndex: index })
  646. }
  647. onVerticalSelectedIndexChange(index: number) {
  648. /* tslint:disable: no-console */
  649. console.log('vertical change to', index)
  650. }
  651. render() {
  652. return (
  653. <ScrollView style={{ paddingTop: 30 }}>
  654. <View style={{ paddingHorizontal: 15 }}>
  655. <Text>horizontal</Text>
  656. <Carousel
  657. style={styles.wrapper}
  658. selectedIndex={this.state.selectedIndex}
  659. autoplay
  660. infinite
  661. afterChange={this.onHorizontalSelectedIndexChange}
  662. ref={(ref) => (this.carousel = ref)}>
  663. <View
  664. style={[styles.containerHorizontal, { backgroundColor: 'red' }]}>
  665. <Text>Carousel 1</Text>
  666. </View>
  667. <View
  668. style={[styles.containerHorizontal, { backgroundColor: 'blue' }]}>
  669. <Text>Carousel 2</Text>
  670. </View>
  671. <View
  672. style={[
  673. styles.containerHorizontal,
  674. { backgroundColor: 'yellow' },
  675. ]}>
  676. <Text>Carousel 3</Text>
  677. </View>
  678. <View
  679. style={[styles.containerHorizontal, { backgroundColor: 'aqua' }]}>
  680. <Text>Carousel 4</Text>
  681. </View>
  682. <View
  683. style={[
  684. styles.containerHorizontal,
  685. { backgroundColor: 'fuchsia' },
  686. ]}>
  687. <Text>Carousel 5</Text>
  688. </View>
  689. </Carousel>
  690. <Button onPress={() => this.carousel && this.carousel.goTo(0)}>
  691. Go to 0
  692. </Button>
  693. </View>
  694. <View style={{ paddingHorizontal: 15 }}>
  695. <Text>vertical</Text>
  696. <Carousel
  697. style={styles.wrapper}
  698. selectedIndex={1}
  699. autoplay={this.state.autoplay}
  700. infinite
  701. afterChange={this.onVerticalSelectedIndexChange}
  702. vertical>
  703. <View
  704. style={[styles.containerVertical, { backgroundColor: 'red' }]}>
  705. <Text>Carousel 1</Text>
  706. </View>
  707. <View
  708. style={[styles.containerVertical, { backgroundColor: 'blue' }]}>
  709. <Text>Carousel 2</Text>
  710. </View>
  711. <View
  712. style={[styles.containerVertical, { backgroundColor: 'yellow' }]}>
  713. <Text>Carousel 3</Text>
  714. </View>
  715. <View
  716. style={[styles.containerVertical, { backgroundColor: 'aqua' }]}>
  717. <Text>Carousel 4</Text>
  718. </View>
  719. <View
  720. style={[
  721. styles.containerVertical,
  722. { backgroundColor: 'fuchsia' },
  723. ]}>
  724. <Text>Carousel 5</Text>
  725. </View>
  726. </Carousel>
  727. <Button
  728. onPress={() => this.setState({ autoplay: !this.state.autoplay })}>
  729. {`Toggle autoplay ${this.state.autoplay ? 'true' : 'false'}`}
  730. </Button>
  731. </View>
  732. </ScrollView>
  733. )
  734. }
  735. }
  736. const styles = StyleSheet.create<{
  737. wrapper: ViewStyle
  738. containerHorizontal: ViewStyle
  739. containerVertical: ViewStyle
  740. text: TextStyle
  741. }>({
  742. wrapper: {
  743. backgroundColor: '#fff',
  744. width: '100%',
  745. height: 150,
  746. },
  747. containerHorizontal: {
  748. flexGrow: 1,
  749. alignItems: 'center',
  750. justifyContent: 'center',
  751. },
  752. containerVertical: {
  753. flexGrow: 1,
  754. alignItems: 'center',
  755. justifyContent: 'center',
  756. },
  757. text: {
  758. color: '#fff',
  759. fontSize: 36,
  760. },
  761. })
  762. ```
  763. ## API
  764. Properties | Descrition | Type | Default | Version
  765. -----------|------------|------|---------|----------
  766. | afterChange | callback to be called after a slide is changed | (current: number) => void | | |
  767. | autoplay | autoplay mode active | Boolean | false | |
  768. | autoplayInterval | interval for autoplay iteration | Number | 3000 | |
  769. | dots | whether to display the indication dots | Boolean | true | |
  770. | dotStyle | style of dots | ViewStyle | | |
  771. | dotActiveStyle | style of active dot | ViewStyle | | |
  772. | infinite | whether is infinite loop | Boolean | false | |
  773. | lazy | Function which takes an object with the current page and returns a boolean to indicate whether to lazily render the scenes. | Boolean \| `(index:number) => boolean` | false | `5.3.1` |
  774. | renderLazyPlaceholder | A callback that returns a custom React Element to render for pages not yet rendered. Requires the `lazy` prop to be enabled. | `(index:number) => ReactNode` | - | `5.3.1` |
  775. | pageStyle | style of the carousel page | ViewStyle | | |
  776. | pagination | A generator function which could be used to customized pagination. | (props) => ReactNode | | |
  777. | selectedIndex | current selected index | number | 0 | |
  778. | style | ScrollView style<br/>(`tips: Recommended setting, the overall carousel size is determined by the container scrollview and not the inner page`) | ViewStyle | | |
  779. | vertical | controls the pagination display direction. | Boolean | false | |
  780. | onScrollAnimationEnd | Called when a scrolling animation ends. | ()=>void | | `5.3.0` |
  781. The rest of the props of Carousel are exactly the same as the react-native [ScrollView](https://reactnative.dev/docs/scrollview.html);
  782. eg: `scrollEnabled`、`onScroll` (if it not works, it is a mandatory prop of Carousel)
  783. ## Carousel ref methods
  784. Properties | Descrition | Type
  785. ----|-----|------
  786. | goTo | jump to specified index | `(index: number, animated?: boolean): void` |
  787. | scrollNextPage | scroll to next page | `() => void` |
  788. ## FAQ
  789. ### 1. On the Android platform, when using `Carousel` nested in `ScrollView`, the Carousel Item cannot slide. What should I do?
  790. Support in `5.1.3`. Set the `nestedScrollEnabled` property of `ScrollView` to `true`.
  791. ```jsx
  792. <ScrollView nestedScrollEnabled={true}>
  793. ...
  794. <Carousel vertical/>
  795. </ScrollView>
  796. ```
  797. ### 2. Use `lazy` and `renderLazyPlaceholder` props to render routes as needed
  798. Support in `5.3.1`.
  799. ```jsx
  800. // `lazy={true}` only the current page is rendered
  801. <Carousel
  802. lazy
  803. renderLazyPlaceholder={()=> <Loading /> }
  804. />
  805. // eg: Render the sibling pages, a total of 3 pages
  806. <Carousel
  807. lazy={(i) => Math.abs(selectedIndex - i) < 2}
  808. >
  809. ```
  810. ### 3. Why choose Carousel instead of `react-native-pager-view` ?
  811. First, Carousel supports the `infinite` property, which means 🌟a true infinite loop🌟. <br/>
  812. Second, Carousel is completely based on `ScrollView`, which is not only lighter but also more compatible.
  813. ---
  814. ## Checkbox
  815. Source: https://rn.mobile.ant.design/components/checkbox.md
  816. # Checkbox
  817. Checkbox
  818. ## Examples
  819. ```tsx
  820. import { Button, Checkbox, Flex, List, WingBlank } from '@ant-design/react-native'
  821. import React from 'react'
  822. import { ScrollView } from 'react-native'
  823. const AgreeItem = Checkbox.AgreeItem
  824. const CheckboxItem = Checkbox.CheckboxItem
  825. export default class BasicCheckboxExample extends React.Component<any, any> {
  826. constructor(props: any, context: any) {
  827. super(props, context)
  828. this.state = {
  829. checked: true,
  830. disabled: false,
  831. checkBox1: true,
  832. agreeItem1: true,
  833. checkboxItem1: true,
  834. }
  835. }
  836. onChange = (e: { target: { checked: boolean } }) => {
  837. console.log(`checked = ${e.target.checked}`)
  838. }
  839. toggleChecked = () => {
  840. this.setState({ checked: !this.state.checked })
  841. }
  842. toggleDisable = () => {
  843. this.setState({ disabled: !this.state.disabled })
  844. }
  845. onChange2 = (e: { target: { checked: boolean } }) => {
  846. console.log('checked = ', e.target.checked)
  847. this.setState({
  848. checked: e.target.checked,
  849. })
  850. }
  851. render() {
  852. const label = `${this.state.checked ? 'Checked' : 'Unchecked'}-${
  853. this.state.disabled ? 'Disabled' : 'Enabled'
  854. }`
  855. return (
  856. <ScrollView>
  857. <List renderHeader="基本用法">
  858. <List.Item
  859. thumb={<Checkbox onChange={this.onChange}>Checkbox</Checkbox>}
  860. />
  861. </List>
  862. <List renderHeader="不可用">
  863. <List.Item thumb={<Checkbox defaultChecked={false} disabled />} />
  864. <List.Item thumb={<Checkbox defaultChecked disabled />} />
  865. </List>
  866. <List
  867. renderHeader="受控的Checkbox"
  868. renderFooter={
  869. <Flex>
  870. <Flex.Item style={{ margin: 10 }}>
  871. <Button
  872. type="primary"
  873. size="small"
  874. onPress={this.toggleChecked}>
  875. {!this.state.checked ? 'Check' : 'Uncheck'}
  876. </Button>
  877. </Flex.Item>
  878. <Flex.Item style={{ margin: 10 }}>
  879. <Button
  880. type="primary"
  881. size="small"
  882. onPress={this.toggleDisable}>
  883. {!this.state.disabled ? 'Disable' : 'Enable'}
  884. </Button>
  885. </Flex.Item>
  886. </Flex>
  887. }>
  888. <List.Item
  889. thumb={
  890. <Checkbox
  891. checked={this.state.checked}
  892. disabled={this.state.disabled}
  893. onChange={this.onChange2}>
  894. {label}
  895. </Checkbox>
  896. }
  897. />
  898. </List>
  899. <List renderHeader="AgreeItem">
  900. <AgreeItem>
  901. Agree agreement agreement agreement agreement agreement agreement
  902. agreement
  903. </AgreeItem>
  904. </List>
  905. <List renderHeader="CheckboxItem">
  906. <CheckboxItem
  907. checked={this.state.checkboxItem1}
  908. onChange={(event) => {
  909. this.setState({ checkboxItem1: event.target.checked })
  910. }}>
  911. Option 1
  912. </CheckboxItem>
  913. <CheckboxItem>Option 2</CheckboxItem>
  914. <CheckboxItem disabled>Option 3</CheckboxItem>
  915. <CheckboxItem disabled checked right>
  916. More...
  917. </CheckboxItem>
  918. </List>
  919. <List
  920. renderHeader={
  921. '全选\n在实现全选效果时,你可能会用到 indeterminate 属性。'
  922. }>
  923. <CheckboxGroupExample />
  924. </List>
  925. </ScrollView>
  926. )
  927. }
  928. }
  929. const plainOptions = ['Apple', 'Pear', 'Orange']
  930. const defaultCheckedList = ['Apple', 'Orange']
  931. const CheckboxGroupExample = () => {
  932. const [checkedList, setCheckedList] = React.useState(
  933. new Set(defaultCheckedList),
  934. )
  935. const [indeterminate, setIndeterminate] = React.useState(true)
  936. const [checkAll, setCheckAll] = React.useState(false)
  937. const onChange = (value: any, e: { target: { checked: boolean } }) => {
  938. if (e.target.checked) {
  939. checkedList.add(value)
  940. } else {
  941. checkedList.delete(value)
  942. }
  943. setCheckedList(new Set(checkedList))
  944. setIndeterminate(
  945. !!checkedList.size && checkedList.size < plainOptions.length,
  946. )
  947. setCheckAll(checkedList.size === plainOptions.length)
  948. }
  949. const onCheckAllChange = (e: { target: { checked: boolean } }) => {
  950. setCheckedList(e.target.checked ? new Set(plainOptions) : new Set())
  951. setIndeterminate(false)
  952. setCheckAll(e.target.checked)
  953. }
  954. return (
  955. <>
  956. <CheckboxItem
  957. indeterminate={indeterminate}
  958. onChange={onCheckAllChange}
  959. checked={checkAll}>
  960. Check all
  961. </CheckboxItem>
  962. <WingBlank>
  963. {plainOptions.map((a) => (
  964. <CheckboxItem
  965. key={a}
  966. onChange={onChange.bind(this, a)}
  967. checked={checkedList.has(a)}>
  968. {a}
  969. </CheckboxItem>
  970. ))}
  971. </WingBlank>
  972. </>
  973. )
  974. }
  975. ```
  976. ## API
  977. ### Checkbox
  978. ```ts
  979. type Event = { target: { checked: boolean } }
  980. ```
  981. Properties | Descrition | Type | Default
  982. -----------|------------|------|--------
  983. | defaultChecked | whether is checked when init | Boolean | |
  984. | checked | whether is checked now (Controlled Mode) | Boolean | |
  985. | disabled | whether is been disabled | Boolean | false |
  986. | indeterminate | The indeterminate checked state of checkbox | Boolean | false |
  987. | onChange | callback when check status is changed | (e: `Event`) => void | |
  988. ### Checkbox.CheckboxItem
  989. The encapsulation about `Checkbox` based on `List.Item`, the property `thumb` of `List.Item` will be passed to `Checkbox`, while other properties remain the same.
  990. Other APIs are identical with `Checkbox`.
  991. ### Checkbox.AgreeItem
  992. Almost the same as CheckboxItem and be used for special scenes. See demo for details.
  993. ---
  994. ## Collapse
  995. Source: https://rn.mobile.ant.design/components/collapse.md
  996. # Collapse
  997. A content area that can be collapsed/expanded.
  998. ### Rules
  999. - Group and hide complex areas to keep pages tidy.
  1000. - An accordion is a special type of accordion panel that only allows a single content area to expand.
  1001. ## Examples
  1002. ```tsx
  1003. import { ActivityIndicator, Collapse, Icon, List, Result } from '@ant-design/react-native'
  1004. import React, { useEffect, useState } from 'react'
  1005. import { ScrollView } from 'react-native'
  1006. export default function CollapseExmple() {
  1007. return (
  1008. <ScrollView>
  1009. <List renderHeader="手风琴模式">
  1010. <Collapse accordion>
  1011. <Collapse.Panel key="1" title="第一项">
  1012. 手风琴模式只能同时展开一个
  1013. </Collapse.Panel>
  1014. <Collapse.Panel key="2" title="第二项">
  1015. 手风琴模式只能同时展开一个
  1016. </Collapse.Panel>
  1017. <Collapse.Panel key="3" title="第三项">
  1018. 手风琴模式只能同时展开一个
  1019. </Collapse.Panel>
  1020. </Collapse>
  1021. </List>
  1022. <List renderHeader="自定义折叠图标">
  1023. <Collapse
  1024. defaultActiveKey={['1']}
  1025. arrow={(active) =>
  1026. active ? <Icon name="minus" /> : <Icon name="plus" />
  1027. }>
  1028. <Collapse.Panel key="1" title="第一项">
  1029. 你可以通过 Collapse 的 arrow 属性来控制全部面板的箭头
  1030. </Collapse.Panel>
  1031. <Collapse.Panel
  1032. key="2"
  1033. title="第二项"
  1034. arrow={<Icon name="down-circle" />}>
  1035. 也可以通过 Collapse.Panel 的 arrow 属性来自定义单个面板的箭头
  1036. </Collapse.Panel>
  1037. <Collapse.Panel
  1038. key="3"
  1039. title="第三项"
  1040. arrow={(active) =>
  1041. active ? (
  1042. <Icon name="check-circle" />
  1043. ) : (
  1044. <Icon name="close-circle" />
  1045. )
  1046. }>
  1047. 如果你给 arrow 属性传入的是是一个渲染函数,那么
  1048. @ant-design/react-native 不会为你增加动画,arrow
  1049. 属性的效果就完全交由你自己来控制了
  1050. </Collapse.Panel>
  1051. </Collapse>
  1052. </List>
  1053. <List renderHeader="动态内容">
  1054. <Collapse accordion>
  1055. <Collapse.Panel key="1" title="第一项" destroyOnClose>
  1056. <DynamicContent message="不可见时销毁 destroyOnClose={true}" />
  1057. </Collapse.Panel>
  1058. <Collapse.Panel key="2" title="第二项" forceRender>
  1059. <DynamicContent message="预加载 forceRender={true}" />
  1060. </Collapse.Panel>
  1061. </Collapse>
  1062. </List>
  1063. </ScrollView>
  1064. )
  1065. }
  1066. function DynamicContent(props: { message: string }) {
  1067. const [finished, setFinished] = useState(false)
  1068. useEffect(() => {
  1069. const loadData = async () => {
  1070. setTimeout(() => {
  1071. setFinished(true)
  1072. }, 1000)
  1073. }
  1074. loadData()
  1075. }, [])
  1076. return finished ? (
  1077. <Result title="处理成功" message={props.message} />
  1078. ) : (
  1079. <ActivityIndicator />
  1080. )
  1081. }
  1082. ```
  1083. ## API
  1084. ### Collapse
  1085. Properties | Descrition | Type | Default |
  1086. -----------|------------|------|---------|
  1087. | accordion | Whether to enable accordion mode | `Boolean` | `false` |
  1088. | activeKey | The `key` of the currently expanded panel | accordion mode: `string | null` <br/> non-accordion mode: `string[]` | - |
  1089. | arrowIcon | Custom arrow icon. <br/>if you pass a ReactNode, will add a rotate animation for you. | `ReactNode | ((active: boolean) => React.ReactNode)` | - |
  1090. | defaultActiveKey | The `key` of the expanded panel by default | accordion mode: `string | null` <br/> non-accordion mode: `string[]` | - |
  1091. | onChange | Triggered when the panel is switched | accordion mode: `(activeKey: string | null) => void` <br/> non-accordion mode: `(activeKey: string[]) => void` | - |
  1092. | styles | Semantic DOM style | Same as [ListStyle](/components/list#liststyle-interface) & [ListItemStyle](/components/list#listitemstyle-interface) | - |
  1093. ### Collapse.Panel
  1094. Properties | Descrition | Type | Default |
  1095. -----------|------------|------|---------|
  1096. | arrowIcon | Custom arrow icon | `ReactNode | ((active: boolean) => React.ReactNode)` | - |
  1097. | destroyOnClose | Destroy `dom` when not visible | `Boolean` | `false` |
  1098. | disabled | Whether disabled or not | `Boolean` | `false` |
  1099. | forceRender | Whether to render the `DOM` structure when hidden | `Boolean` | `false` |
  1100. | key | The unique identifier | `String` | - |
  1101. | onPress | The click event of title bar | `(event: GestureResponderEvent) => void` | - |
  1102. | styles | Semantic DOM style | Same as [ListStyle](/components/list#liststyle-interface) | - |
  1103. | title | The content on the left side of the title bar | `ReactNode` | - |
  1104. ---
  1105. ## DatePicker
  1106. Source: https://rn.mobile.ant.design/components/date-picker.md
  1107. # DatePicker
  1108. Used to select a date or time.
  1109. ### Rules
  1110. - At most accurate to seconds.
  1111. ## Examples
  1112. ```tsx
  1113. import { DatePicker, List, Provider } from '@ant-design/react-native'
  1114. import React from 'react'
  1115. export default class PopupExample extends React.Component<any, any> {
  1116. constructor(props: any) {
  1117. super(props)
  1118. this.state = {
  1119. value: undefined,
  1120. }
  1121. }
  1122. onChange = (value: any) => {
  1123. this.setState({ value })
  1124. }
  1125. render() {
  1126. return (
  1127. <Provider>
  1128. <List>
  1129. <DatePicker
  1130. value={this.state.value}
  1131. precision="day"
  1132. minDate={new Date(2015, 7, 6)}
  1133. maxDate={new Date(2026, 11, 3)}
  1134. onChange={this.onChange}
  1135. format="YYYY-MM-DD">
  1136. <List.Item arrow="horizontal">Select Date</List.Item>
  1137. </DatePicker>
  1138. </List>
  1139. </Provider>
  1140. )
  1141. }
  1142. }
  1143. ```
  1144. ## API
  1145. ```ts
  1146. type Precision =
  1147. | 'week'
  1148. | 'week-day'
  1149. | 'year'
  1150. | 'month'
  1151. | 'day'
  1152. | 'hour'
  1153. | 'minute'
  1154. | 'second'
  1155. type DatePickerFilter = Partial<
  1156. Record<
  1157. Precision,
  1158. (
  1159. val: number,
  1160. extend: {
  1161. date: Date
  1162. }
  1163. ) => boolean
  1164. >
  1165. >
  1166. ```
  1167. Properties | Descrition | Type | Default | Version
  1168. -----------|------------|------|--------|--------
  1169. | precision | Precision | `Precision` | `day` |`5.1.0`|
  1170. | value | the currently selected value | Date | - ||
  1171. | defaultValue | the default selected value | Date | - ||
  1172. | minDate | minimum date | Date | 2000-1-1 ||
  1173. | maxDate | maximum date | Date | 2030-1-1 ||
  1174. | onChange | change handler | `(value: Date) => void` | - ||
  1175. | onValueChange | fire when picker col change | `(value: Date, index: number) => void` | - ||
  1176. | renderLabel | The function to custom rendering the label shown on a column. `type` means any value in `precision`, `data` means the default number | `(type:Precision / 'now', data: number) => ReactNode` | - ||
  1177. | locale | international, can override the configuration of the global [Provider](/components/provider)'s `locale` | Object: Object: {okText, dismissText, extra, `DatePickerLocale:{ year,month,day,hour,minute,am,pm }`} | - |
  1178. | filter | Filter available time | `DatePickerFilter` | - | `5.1.0` |
  1179. In addition, the following properties of [Picker](/components/picker) are supported: `onPickerChange` `onVisibleChange` `style` `styles` `itemStyle` `itemHeight` `numberOfLines` `title` `okText` `dismissText` `okButtonProps` `dismissButtonProps` `visible` `children` `renderMaskTop` `renderMaskBottom`
  1180. ### Children
  1181. Same as [Picker](/components/picker#children), except type `format` is different:
  1182. Properties | Descrition | Type | Default
  1183. ----|-----|------|------
  1184. | format | format the selected value |`(value: Date) => date string` | import [Day.js Format](https://day.js.org/docs/en/parse/string-format), precision:`YYYY-MM-DD`,`YYYY-MM-DD HH:mm:ss`|
  1185. ### Ref
  1186. Same as [Picker](/components/picker#ref)
  1187. ---
  1188. ## DatePickerView
  1189. Source: https://rn.mobile.ant.design/components/date-picker-view.md
  1190. # DatePickerView
  1191. DatePickerView's functions like DatePicker, but it is rendered directly in the area instead of the pop-up window.
  1192. ## Examples
  1193. ```tsx
  1194. import { DatePickerView, DatePickerFilter } from '@ant-design/react-native'
  1195. import React, { useState } from 'react'
  1196. import { ScrollView, Text } from 'react-native'
  1197. const now = new Date()
  1198. export default () => {
  1199. const [value, setValue] = useState<Date>(now)
  1200. return (
  1201. <ScrollView nestedScrollEnabled>
  1202. <Text style={{ margin: 16 }}>基础用法</Text>
  1203. <DatePickerView />
  1204. <Text style={{ margin: 16 }}>受控模式</Text>
  1205. <DatePickerView
  1206. value={value}
  1207. onChange={(val) => {
  1208. setValue(val)
  1209. console.log('onChange', val)
  1210. }}
  1211. />
  1212. <Text style={{ margin: 16 }}>自定义每列的渲染内容</Text>
  1213. <DatePickerView defaultValue={now} renderLabel={labelRenderer} />
  1214. <Text style={{ margin: 16 }}>周选择器</Text>
  1215. <DatePickerView
  1216. onChange={(val) => console.log('onChange', val)}
  1217. precision="week-day"
  1218. defaultValue={now}
  1219. renderLabel={weekdayLabelRenderer}
  1220. />
  1221. <Text style={{ margin: 16 }}>过滤可供选择的时间</Text>
  1222. <DatePickerView
  1223. defaultValue={now}
  1224. precision="hour"
  1225. renderLabel={labelRenderer}
  1226. filter={dateFilter}
  1227. />
  1228. </ScrollView>
  1229. )
  1230. }
  1231. const labelRenderer = (type: string, data: number) => {
  1232. switch (type) {
  1233. case 'year':
  1234. return data + '年'
  1235. case 'month':
  1236. return data + '月'
  1237. case 'day':
  1238. return data + '日'
  1239. case 'hour':
  1240. return data + '时'
  1241. case 'minute':
  1242. return data + '分'
  1243. case 'second':
  1244. return data + '秒'
  1245. default:
  1246. return data
  1247. }
  1248. }
  1249. const weekdayLabelRenderer = (type: string, data: number) => {
  1250. switch (type) {
  1251. case 'year':
  1252. return data + '年'
  1253. case 'week':
  1254. return data + '周'
  1255. case 'week-day':
  1256. return weekdayToZh(data)
  1257. default:
  1258. return data
  1259. }
  1260. }
  1261. const dateFilter: DatePickerFilter = {
  1262. day: (_val, { date }) => {
  1263. // 去除所有周末
  1264. if (date.getDay() > 5 || date.getDay() === 0) {
  1265. return false
  1266. }
  1267. return true
  1268. },
  1269. hour: (val: number) => {
  1270. // 只保留每天的14点到18点
  1271. if (val < 14 || val > 18) {
  1272. return false
  1273. }
  1274. return true
  1275. },
  1276. }
  1277. const weekdayToZh = (weekday: number) => {
  1278. switch (weekday) {
  1279. case 1:
  1280. return '周一'
  1281. case 2:
  1282. return '周二'
  1283. case 3:
  1284. return '周三'
  1285. case 4:
  1286. return '周四'
  1287. case 5:
  1288. return '周五'
  1289. case 6:
  1290. return '周六'
  1291. case 7:
  1292. return '周日'
  1293. default:
  1294. return weekday
  1295. }
  1296. }
  1297. ```
  1298. ## API
  1299. ```ts
  1300. type Precision =
  1301. | 'week'
  1302. | 'week-day'
  1303. | 'year'
  1304. | 'month'
  1305. | 'day'
  1306. | 'hour'
  1307. | 'minute'
  1308. | 'second'
  1309. type DatePickerFilter = Partial<
  1310. Record<
  1311. Precision,
  1312. (
  1313. val: number,
  1314. extend: {
  1315. date: Date
  1316. }
  1317. ) => boolean
  1318. >
  1319. >
  1320. ```
  1321. Properties | Descrition | Type | Default | Version
  1322. -----------|------------|------|---------|---------
  1323. | precision | Precision | `Precision` | `day` |`5.1.0`|
  1324. | value | the currently selected value | Date | - |
  1325. | defaultValue | the default selected value | Date | - ||
  1326. | minDate | minimum date | Date | 2000-1-1 |
  1327. | maxDate | maximum date | Date | 2030-1-1 |
  1328. | onChange | change handler | `(value: Date) => void` | - ||
  1329. | onValueChange | fire when picker col change | `(value: Date, index: number) => void` | - ||
  1330. | renderLabel | The function to custom rendering the label shown on a column. `type` means any value in `precision`, `data` means the default number | `(type:Precision / 'now', data: number) => ReactNode` | - ||
  1331. | filter | Filter available time | `DatePickerFilter` | - | `5.1.0` |
  1332. In addition, the following properties of [PickerView](/components/picker-view) are supported: `style` `styles` `itemStyle` `itemHeight` `numberOfLines` `renderMaskTop` `renderMaskBottom`
  1333. ---
  1334. ## DatePickerView
  1335. Source: https://rn.mobile.ant.design/components/image-picker.md
  1336. # DatePickerView
  1337. Deprecated since `5.1.0`.
  1338. ---
  1339. ## Drawer
  1340. Source: https://rn.mobile.ant.design/components/drawer.md
  1341. # Drawer
  1342. Drawer is a panel that displays the app's navigation options on the left edge of the screen.
  1343. ### Rules
  1344. - Recommended way to show navigation options on Android, it is a common pattern found in Android APPs.
  1345. ## Examples
  1346. ```tsx
  1347. import { Button, Drawer, List, WhiteSpace } from '@ant-design/react-native'
  1348. import React from 'react'
  1349. import { ScrollView, StyleSheet, Text, View } from 'react-native'
  1350. const styles = StyleSheet.create({
  1351. container: {
  1352. flex: 1,
  1353. },
  1354. })
  1355. export default class DrawerExample extends React.Component<any, any> {
  1356. drawer: any
  1357. onOpenChange = (isOpen: any) => {
  1358. /* tslint:disable: no-console */
  1359. console.log('是否打开了 Drawer', isOpen.toString())
  1360. }
  1361. render() {
  1362. const itemArr = Array.apply(null, Array(20))
  1363. .map(function (_: any, i: any) {
  1364. return i
  1365. })
  1366. .map((_i: any, index: any) => {
  1367. if (index === 0) {
  1368. return (
  1369. <List.Item
  1370. key={index}
  1371. thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
  1372. multipleLine>
  1373. <View
  1374. style={{
  1375. flexDirection: 'row',
  1376. justifyContent: 'space-between',
  1377. alignItems: 'center',
  1378. }}>
  1379. <Text>Categories - {index}</Text>
  1380. <Button
  1381. type="primary"
  1382. size="small"
  1383. onPress={() => this.drawer.closeDrawer()}>
  1384. close drawer
  1385. </Button>
  1386. </View>
  1387. </List.Item>
  1388. )
  1389. }
  1390. return (
  1391. <List.Item
  1392. key={index}
  1393. thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png">
  1394. <Text>Categories - {index}</Text>
  1395. </List.Item>
  1396. )
  1397. })
  1398. // Todo: https://github.com/DefinitelyTyped/DefinitelyTyped
  1399. const sidebar = (
  1400. <ScrollView style={[styles.container as any]}>
  1401. <List>{itemArr}</List>
  1402. </ScrollView>
  1403. )
  1404. return (
  1405. <Drawer
  1406. sidebar={sidebar}
  1407. position="left"
  1408. open={false}
  1409. drawerRef={(el: any) => (this.drawer = el)}
  1410. onOpenChange={this.onOpenChange}
  1411. drawerBackgroundColor="#ccc">
  1412. <View style={{ flex: 1, marginTop: 114, padding: 8 }}>
  1413. <Button onPress={() => this.drawer && this.drawer.openDrawer()}>
  1414. Open drawer
  1415. </Button>
  1416. <WhiteSpace />
  1417. </View>
  1418. </Drawer>
  1419. )
  1420. }
  1421. }
  1422. ```
  1423. ## API
  1424. Properties | Descrition | Type | Default
  1425. -----------|------------|------|--------
  1426. | sidebar | The sidebar content. | ReactNode | - |
  1427. | onOpenChange | Callback called when open state of `Drawer` changes. | (open: bool): void | - |
  1428. | open | If the sidebar should be open. | Boolean | false |
  1429. | position | Position of `Drawer`. | String | 'left', enum{'left', 'right'} |
  1430. | drawerWidth | Width of `Drawer` | Number | 300 |
  1431. | drawerBackgroundColor | Background color of `Drawer` | String | - |
  1432. | openDrawer | Opens the `Drawer`. | (): void | - |
  1433. | closeDrawer | Closes the `Drawer`. | (): void | - |
  1434. ---
  1435. ## Flex
  1436. Source: https://rn.mobile.ant.design/components/flex.md
  1437. # Flex
  1438. Flex is a wrap of Flexible Box.
  1439. ## Examples
  1440. ```tsx
  1441. import { Button, Flex, WhiteSpace, WingBlank } from '@ant-design/react-native'
  1442. import React from 'react'
  1443. import { ScrollView, Text, TouchableWithoutFeedback, View } from 'react-native'
  1444. const Circle = (props: any) => {
  1445. const size = props.size || 20
  1446. const style = {
  1447. borderRadius: size / 2,
  1448. backgroundColor: '#527fe4',
  1449. width: size,
  1450. height: size,
  1451. margin: 1,
  1452. }
  1453. return <View style={style} />
  1454. }
  1455. export default class FlexExample extends React.Component<any, any> {
  1456. render() {
  1457. return (
  1458. <ScrollView
  1459. style={{ flex: 1 }}
  1460. automaticallyAdjustContentInsets={false}
  1461. showsHorizontalScrollIndicator={false}
  1462. showsVerticalScrollIndicator={false}>
  1463. <WingBlank style={{ marginTop: 20, marginBottom: 5 }}>
  1464. <Text style={{ marginBottom: 10 }}>项目的排列方向</Text>
  1465. <Text>direction="row":主轴为水平方向,起点在左端</Text>
  1466. </WingBlank>
  1467. <WingBlank style={{ marginBottom: 5 }}>
  1468. <Flex>
  1469. <Flex.Item style={{ paddingLeft: 4, paddingRight: 4 }}>
  1470. <Button size="small">按钮1</Button>
  1471. </Flex.Item>
  1472. <Flex.Item style={{ paddingLeft: 4, paddingRight: 4 }}>
  1473. <Button size="small">按钮2</Button>
  1474. </Flex.Item>
  1475. <Flex.Item style={{ paddingLeft: 4, paddingRight: 4 }}>
  1476. <Button size="small">按钮3</Button>
  1477. </Flex.Item>
  1478. </Flex>
  1479. </WingBlank>
  1480. <WingBlank style={{ marginTop: 5, marginBottom: 5 }}>
  1481. <Text>direction="column":主轴为垂直方向,起点在上沿</Text>
  1482. </WingBlank>
  1483. <WingBlank style={{ marginBottom: 5 }}>
  1484. <Flex direction="column">
  1485. <Flex.Item style={{ paddingBottom: 4 }}>
  1486. <Button size="small">按钮1</Button>
  1487. </Flex.Item>
  1488. <Flex.Item style={{ paddingBottom: 4 }}>
  1489. <Button size="small">按钮2</Button>
  1490. </Flex.Item>
  1491. <Flex.Item style={{ paddingBottom: 4 }}>
  1492. <Button size="small">按钮3</Button>
  1493. </Flex.Item>
  1494. </Flex>
  1495. </WingBlank>
  1496. <WingBlank style={{ marginTop: 5, marginBottom: 5 }}>
  1497. <Text style={{ marginTop: 20, marginBottom: 20 }}>
  1498. 项目在主轴上的对齐方式
  1499. </Text>
  1500. <Text>justify="start":左对齐</Text>
  1501. </WingBlank>
  1502. <WingBlank style={{ marginBottom: 5 }}>
  1503. <Flex justify="start">
  1504. <Circle />
  1505. <Circle />
  1506. <Circle />
  1507. <Circle />
  1508. <Circle />
  1509. </Flex>
  1510. </WingBlank>
  1511. <WingBlank style={{ marginTop: 5, marginBottom: 5 }}>
  1512. <Text>justify="center":居中</Text>
  1513. </WingBlank>
  1514. <WingBlank style={{ marginBottom: 5 }}>
  1515. <Flex justify="center">
  1516. <Circle />
  1517. <Circle />
  1518. <Circle />
  1519. <Circle />
  1520. <Circle />
  1521. </Flex>
  1522. </WingBlank>
  1523. <WingBlank style={{ marginTop: 5, marginBottom: 5 }}>
  1524. <Text>justify="end":右对齐</Text>
  1525. </WingBlank>
  1526. <WingBlank style={{ marginBottom: 5 }}>
  1527. <Flex justify="end">
  1528. <Circle />
  1529. <Circle />
  1530. <Circle />
  1531. <Circle />
  1532. <Circle />
  1533. </Flex>
  1534. </WingBlank>
  1535. <WingBlank style={{ marginTop: 5, marginBottom: 5 }}>
  1536. <Text>justify="between":两端对齐,项目之间的间隔都相等</Text>
  1537. </WingBlank>
  1538. <WingBlank style={{ marginBottom: 5 }}>
  1539. <Flex justify="between">
  1540. <Circle />
  1541. <Circle />
  1542. <Circle />
  1543. <Circle />
  1544. <Circle />
  1545. </Flex>
  1546. </WingBlank>
  1547. <WingBlank style={{ marginTop: 5, marginBottom: 5 }}>
  1548. <Text>justify="around":每个项目两侧的间隔相等</Text>
  1549. </WingBlank>
  1550. <WingBlank style={{ marginBottom: 5 }}>
  1551. <Flex justify="around">
  1552. <Circle />
  1553. <Circle />
  1554. <Circle />
  1555. <Circle />
  1556. <Circle />
  1557. </Flex>
  1558. </WingBlank>
  1559. <WingBlank style={{ marginTop: 5, marginBottom: 5 }}>
  1560. <Text style={{ marginTop: 20, marginBottom: 20 }}>
  1561. 项目在交叉轴上的对齐方式
  1562. </Text>
  1563. <Text>align="start":交叉轴的起点对齐</Text>
  1564. </WingBlank>
  1565. <WingBlank style={{ marginBottom: 5 }}>
  1566. <Flex align="start" style={{ height: 30 }}>
  1567. <Text
  1568. style={{
  1569. fontSize: 20,
  1570. borderWidth: 1,
  1571. borderStyle: 'solid',
  1572. borderColor: '#527fe4',
  1573. }}>
  1574. 兜兜
  1575. </Text>
  1576. <Text
  1577. style={{
  1578. fontSize: 18,
  1579. borderWidth: 1,
  1580. borderStyle: 'solid',
  1581. borderColor: '#527fe4',
  1582. }}>
  1583. 兜兜
  1584. </Text>
  1585. <Text
  1586. style={{
  1587. fontSize: 16,
  1588. borderWidth: 1,
  1589. borderStyle: 'solid',
  1590. borderColor: '#527fe4',
  1591. }}>
  1592. 兜兜
  1593. </Text>
  1594. <Text
  1595. style={{
  1596. fontSize: 14,
  1597. borderWidth: 1,
  1598. borderStyle: 'solid',
  1599. borderColor: '#527fe4',
  1600. }}>
  1601. 兜兜
  1602. </Text>
  1603. </Flex>
  1604. </WingBlank>
  1605. <WingBlank style={{ marginTop: 5, marginBottom: 5 }}>
  1606. <Text>align="center":交叉轴的中点对齐</Text>
  1607. </WingBlank>
  1608. <WingBlank style={{ marginBottom: 5 }}>
  1609. <Flex align="center" style={{ height: 30 }}>
  1610. <Text
  1611. style={{
  1612. fontSize: 20,
  1613. borderWidth: 1,
  1614. borderStyle: 'solid',
  1615. borderColor: '#527fe4',
  1616. }}>
  1617. 兜兜
  1618. </Text>
  1619. <Text
  1620. style={{
  1621. fontSize: 18,
  1622. borderWidth: 1,
  1623. borderStyle: 'solid',
  1624. borderColor: '#527fe4',
  1625. }}>
  1626. 兜兜
  1627. </Text>
  1628. <Text
  1629. style={{
  1630. fontSize: 16,
  1631. borderWidth: 1,
  1632. borderStyle: 'solid',
  1633. borderColor: '#527fe4',
  1634. }}>
  1635. 兜兜
  1636. </Text>
  1637. <Text
  1638. style={{
  1639. fontSize: 14,
  1640. borderWidth: 1,
  1641. borderStyle: 'solid',
  1642. borderColor: '#527fe4',
  1643. }}>
  1644. 兜兜
  1645. </Text>
  1646. </Flex>
  1647. </WingBlank>
  1648. <WingBlank style={{ marginTop: 5, marginBottom: 5 }}>
  1649. <Text>align="end":交叉轴的终点对齐</Text>
  1650. </WingBlank>
  1651. <WingBlank style={{ marginBottom: 5 }}>
  1652. <Flex align="end" style={{ height: 30 }}>
  1653. <Text
  1654. style={{
  1655. fontSize: 20,
  1656. borderWidth: 1,
  1657. borderStyle: 'solid',
  1658. borderColor: '#527fe4',
  1659. }}>
  1660. 兜兜
  1661. </Text>
  1662. <Text
  1663. style={{
  1664. fontSize: 18,
  1665. borderWidth: 1,
  1666. borderStyle: 'solid',
  1667. borderColor: '#527fe4',
  1668. }}>
  1669. 兜兜
  1670. </Text>
  1671. <Text
  1672. style={{
  1673. fontSize: 16,
  1674. borderWidth: 1,
  1675. borderStyle: 'solid',
  1676. borderColor: '#527fe4',
  1677. }}>
  1678. 兜兜
  1679. </Text>
  1680. <Text
  1681. style={{
  1682. fontSize: 14,
  1683. borderWidth: 1,
  1684. borderStyle: 'solid',
  1685. borderColor: '#527fe4',
  1686. }}>
  1687. 兜兜
  1688. </Text>
  1689. </Flex>
  1690. </WingBlank>
  1691. <WingBlank style={{ marginTop: 5, marginBottom: 5 }}>
  1692. <Text>
  1693. align="stretch":如果项目未设置高度或设为auto,将占满整个容器的高度
  1694. </Text>
  1695. </WingBlank>
  1696. <WingBlank style={{ marginBottom: 5 }}>
  1697. <WingBlank>
  1698. <Flex align="stretch" style={{ height: 70 }}>
  1699. <Text
  1700. style={{
  1701. fontSize: 20,
  1702. borderWidth: 1,
  1703. borderStyle: 'solid',
  1704. borderColor: '#527fe4',
  1705. }}>
  1706. 兜兜
  1707. </Text>
  1708. <Text
  1709. style={{
  1710. fontSize: 18,
  1711. borderWidth: 1,
  1712. borderStyle: 'solid',
  1713. borderColor: '#527fe4',
  1714. }}>
  1715. 兜兜
  1716. </Text>
  1717. <Text
  1718. style={{
  1719. fontSize: 16,
  1720. borderWidth: 1,
  1721. borderStyle: 'solid',
  1722. borderColor: '#527fe4',
  1723. }}>
  1724. 兜兜
  1725. </Text>
  1726. <Text
  1727. style={{
  1728. fontSize: 14,
  1729. borderWidth: 1,
  1730. borderStyle: 'solid',
  1731. borderColor: '#527fe4',
  1732. }}>
  1733. 兜兜
  1734. </Text>
  1735. </Flex>
  1736. </WingBlank>
  1737. </WingBlank>
  1738. <WingBlank style={{ marginTop: 5, marginBottom: 5 }}>
  1739. <Text style={{ marginBottom: 10 }}>是否折行</Text>
  1740. <Text>wrap="wrap":换行</Text>
  1741. </WingBlank>
  1742. <WingBlank style={{ marginBottom: 5 }}>
  1743. <TouchableWithoutFeedback onPress={() => ({})}>
  1744. <Flex wrap="wrap">
  1745. {'ooooooooooooooooooooooooooooo'.split('').map((char, i) => (
  1746. <Circle key={`${i}-${char}`} />
  1747. ))}
  1748. </Flex>
  1749. </TouchableWithoutFeedback>
  1750. </WingBlank>
  1751. <WingBlank style={{ marginTop: 5, marginBottom: 5 }}>
  1752. <Text>wrap="nowrap":不换行</Text>
  1753. </WingBlank>
  1754. <WingBlank style={{ marginBottom: 5 }}>
  1755. <Flex wrap="nowrap" onPress={() => ({})}>
  1756. {'ooooooooooooooooooooooooooooo'.split('').map((char, i) => (
  1757. <Circle key={`${i}-${char}`} />
  1758. ))}
  1759. </Flex>
  1760. </WingBlank>
  1761. <WhiteSpace />
  1762. <WhiteSpace />
  1763. <WhiteSpace />
  1764. </ScrollView>
  1765. )
  1766. }
  1767. }
  1768. ```
  1769. ## API
  1770. ### Flex
  1771. Properties | Descrition | Type | Default
  1772. -----------|------------|------|--------
  1773. | direction | how flex items are placed in the flex container,value could be `row`,`row-reverse`,`column`,`column-reverse`, RN only support `row`,`column` | String | `row` |
  1774. | wrap | the wrap way of sub-elements,option `nowrap`,`wrap`,`wrap-reverse`,RN only support `nowrap`,`wrap` | String | `nowrap` |
  1775. | justify | the way of alignment for sub-elements of main axis, option `start`,`end`,`center`,`between`,`around` | String | `start` |
  1776. | align | the way of alignment for sub-elements of cross-axis, option `start`,`center`,`end`,`baseline`,`stretch` RN only support `start`,`end`,`center`,`stretch` | String | `center` |
  1777. ### Flex.Item
  1778. Flex.Item component has style `flex:1` as default, ensure all items average division width, Flex container‘s children maybe not Flex.Item.
  1779. ---
  1780. ## Form
  1781. Source: https://rn.mobile.ant.design/components/form.md
  1782. # Form
  1783. High-performance form component with data domain management. Includes data entry, validation, and corresponding styles. Base on [rc-field-form](https://www.npmjs.com/package/rc-field-form).
  1784. Example from https://ant.design/components/form-cn
  1785. ## When to use
  1786. - When you need to create an instance or collect information.
  1787. - When you need to validate fields in certain rules.
  1788. ## Examples
  1789. ```tsx
  1790. import {
  1791. Button,
  1792. Form,
  1793. Input,
  1794. Picker,
  1795. Provider,
  1796. Radio,
  1797. Flex as Row,
  1798. Switch,
  1799. } from '@ant-design/react-native'
  1800. import type { FormProps } from '@ant-design/react-native/lib/form'
  1801. import { district } from 'antd-mobile-demo-data'
  1802. import React from 'react'
  1803. import { KeyboardAvoidingView, Platform, ScrollView } from 'react-native'
  1804. const Col = Row.Item
  1805. type FieldType = {
  1806. username?: string
  1807. password?: string
  1808. remember?: string
  1809. isDefault?: boolean
  1810. }
  1811. const FormExample: React.FC = () => {
  1812. const [form] = Form.useForm()
  1813. const onSubmit = () => {
  1814. form.submit()
  1815. }
  1816. const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
  1817. console.log('Success:', values)
  1818. }
  1819. const onFinishFailed: FormProps<FieldType>['onFinishFailed'] = (
  1820. errorInfo,
  1821. ) => {
  1822. console.log('Failed:', errorInfo)
  1823. }
  1824. const pickerRef = React.useRef<any>(null)
  1825. return (
  1826. <Provider>
  1827. <KeyboardAvoidingView
  1828. behavior="padding"
  1829. keyboardVerticalOffset={Platform.OS === 'ios' ? 100 : undefined}>
  1830. <ScrollView keyboardShouldPersistTaps="handled">
  1831. <Form
  1832. name="basic"
  1833. form={form}
  1834. onFinish={onFinish}
  1835. onFinishFailed={onFinishFailed}
  1836. initialValues={{
  1837. doorNumber: '',
  1838. username: '',
  1839. phoneNumber: '',
  1840. isDefault: false,
  1841. }}
  1842. renderHeader="水平布局菜单">
  1843. <Form.Item
  1844. label="地址"
  1845. name="address"
  1846. rules={[{ required: true, message: '地址不能为空' }]}
  1847. arrow="horizontal"
  1848. onPress={() => {
  1849. pickerRef.current.toggle()
  1850. }}>
  1851. <Picker data={district} cols={3} ref={pickerRef}>
  1852. {({ extra, value, toggle }) => (
  1853. <Input
  1854. value={value?.length ? extra : undefined}
  1855. onFocus={toggle}
  1856. placeholder="省/市/区"
  1857. />
  1858. )}
  1859. </Picker>
  1860. </Form.Item>
  1861. <Form.Item
  1862. label="收货人"
  1863. name="username"
  1864. extra={
  1865. <Form.Item name="gender" noStyle>
  1866. <Radio.Group>
  1867. <Row>
  1868. <Radio value={1}>先生</Radio>
  1869. <Radio value={2}>女士</Radio>
  1870. </Row>
  1871. </Radio.Group>
  1872. </Form.Item>
  1873. }>
  1874. <Input placeholder="请输入收货人姓名" />
  1875. </Form.Item>
  1876. <Form.Item
  1877. label="手机号"
  1878. name="phoneNumber"
  1879. hasFeedback
  1880. validateDebounce={500}
  1881. rules={[{ pattern: /^1[3456789]\d{9}$/ }, { required: true }]}>
  1882. <Input type="number" placeholder="请输入手机号" />
  1883. </Form.Item>
  1884. <Form.Item
  1885. label="设为默认"
  1886. name="isDefault"
  1887. wrapperStyle={{ alignItems: 'flex-end' }}
  1888. valuePropName="checked">
  1889. <Switch />
  1890. </Form.Item>
  1891. <Form.Item>
  1892. <Row>
  1893. <Col style={{ marginRight: 10 }}>
  1894. <Button onPress={() => form.resetFields()}>重置</Button>
  1895. </Col>
  1896. <Col>
  1897. <Button type="primary" onPress={onSubmit}>
  1898. 保存
  1899. </Button>
  1900. </Col>
  1901. </Row>
  1902. </Form.Item>
  1903. </Form>
  1904. <Form name="vertical" layout="vertical" renderHeader="垂直布局菜单">
  1905. <Form.Item label="问题描述">
  1906. <Input.TextArea
  1907. placeholder="请填写10个字以上的问题描述,以便我们提供更好的服务。"
  1908. maxLength={200}
  1909. showCount
  1910. rows={6}
  1911. />
  1912. </Form.Item>
  1913. <Form.Item
  1914. label="联系电话"
  1915. name="phone"
  1916. help="如您选择填写联系方式,该信息将同步至开发者">
  1917. <Input type="number" placeholder="选填,请填写您的手机号码" />
  1918. </Form.Item>
  1919. </Form>
  1920. </ScrollView>
  1921. </KeyboardAvoidingView>
  1922. </Provider>
  1923. )
  1924. }
  1925. export default FormExample
  1926. ```
  1927. ## API
  1928. ### Form
  1929. | Property | Description | Type | Default |
  1930. | --- | --- | --- | --- |
  1931. | disabled | Set form component disable, only available for `@ant-design/react-native` components | boolean | false |
  1932. | component | Set the Form rendering element. Do not create a ReactNode for `false` | ComponentType \| false | `List` |
  1933. | fields | Control of form fields through state management (such as redux). Not recommended for non-strong demand. View [example](https://ant.design/components/form#components-form-demo-global-state) | [FieldData](#fielddata)\[] | - |
  1934. | form | Form control instance created by `Form.useForm()`. Automatically created when not provided | [FormInstance](#forminstance) | - |
  1935. | feedbackIcons | Can be passed custom icons while `Form.Item` element has `hasFeedback` | [FeedbackIcons](#feedbackicons) | - |
  1936. | initialValues | Set value by Form initialization or reset | object | - |
  1937. | labelStyle | The label style | `ViewStyle \| TextStyle` | - |
  1938. | layout | Form layout | `horizontal` \| `vertical` | `horizontal` |
  1939. | name | Form name. Will be the prefix of Field `id` | string | - |
  1940. | preserve | Keep field value even when field removed. You can get the preserve field value by `getFieldsValue(true)` | boolean | true |
  1941. | requiredMark | Required mark style. Can use required mark or optional mark. You can not config to single Form.Item since this is a Form level config | boolean \| `optional` \| ((label: ReactNode, info: { required: boolean }) => ReactNode) | true |
  1942. | validateMessages | Validation prompt template, description [see below](#validatemessages) | [ValidateMessages](https://github.com/ant-design/ant-design/blob/6234509d18bac1ac60fbb3f92a5b2c6a6361295a/components/locale/en_US.ts#L88-L134) | - |
  1943. | validateTrigger | Config field validate trigger | string \| string\[] | `onChange` |
  1944. | wrapperStyle | The layout for input controls, same as `labelStyle` | `ViewStyle` | - |
  1945. | onFieldsChange | Trigger when field updated | function(changedFields, allFields) | - |
  1946. | onFinish | Trigger after submitting the form and verifying data successfully | function(values) | - |
  1947. | onFinishFailed | Trigger after submitting the form and verifying data failed | function({ values, errorFields, outOfDate }) | - |
  1948. | onValuesChange | Trigger when value updated | function(changedValues, allValues) | - |
  1949. | styles | Semantic DOM style | Same as [ListStyle](/components/list#liststyle-interface) | - |
  1950. ### validateMessages
  1951. Form provides [default verification error messages](https://github.com/ant-design/ant-design/blob/6234509d18bac1ac60fbb3f92a5b2c6a6361295a/components/locale/en_US.ts#L88-L134). You can modify the template by configuring `validateMessages` property. A common usage is to configure localization:
  1952. ```jsx
  1953. const validateMessages = {
  1954. required: "'${name}' is required!",
  1955. // ...
  1956. };
  1957. <Form validateMessages={validateMessages} />;
  1958. ```
  1959. ## Form.Item
  1960. Form field component for data bidirectional binding, validation, layout, and so on.
  1961. | Property | Description | Type | Default |
  1962. | --- | --- | --- | --- |
  1963. | dependencies | Set the dependency field. See [below](#dependencies) | [NamePath](#namepath)\[] | - |
  1964. | getValueFromEvent | Specify how to get value from event or other onChange arguments | (..args: any\[]) => any | - |
  1965. | getValueProps | Additional props with sub component (It's not recommended to generate dynamic function prop by `getValueProps`. Please pass it to child component directly) | (value: any) => Record<string, any> | - |
  1966. | hasFeedback | Used with `validateStatus`, this option specifies the validation status icon. Recommended to be used only with `Input`. Also, It can get feedback icons via icons prop. | boolean \| { icons: [FeedbackIcons](#feedbackicons) } | false |
  1967. | help | The prompt message. If not provided, the prompt message will be generated by the validation rule. | ReactNode | - |
  1968. | hidden | Whether to hide Form.Item (still collect and validate value) | boolean | false |
  1969. | initialValue | Config sub default value. Form `initialValues` get higher priority when conflict | string | - |
  1970. | label | Label text | ReactNode | - |
  1971. | labelStyle | The label style. You can set `labelCol` on Form which will not affect nest Item. If both exists, use Item first | `ViewStyle \| TextStyle` | - |
  1972. | messageVariables | The default validate field info | Record&lt;string, string> | - |
  1973. | name | Field name, support array | [NamePath](#namepath) | - |
  1974. | normalize | Normalize value from component value before passing to Form instance. Do not support async | (value, prevValue, prevValues) => any | - |
  1975. | noStyle | No style for `true`, used as a pure field control. Will inherit parent Form.Item `validateStatus` if self `validateStatus` not configured | boolean | false |
  1976. | preserve | Keep field value even when field removed | boolean | true |
  1977. | required | Display required style. It will be generated by the validation rule | boolean | false |
  1978. | rules | Rules for field validation. Click [here](https://ant.design/components/form#components-form-demo-basic) to see an example | [Rule](#rule)\[] | - |
  1979. | shouldUpdate | Custom field update logic. See [below](#shouldupdate) | boolean \| (prevValue, curValue) => boolean | false |
  1980. | styles | Semantic DOM style | [FormItemStyle](#formitemstyle-interface) & [ValidateStatusStyle](#validatestatusstyle-interface) | - |
  1981. | trigger | When to collect the value of children node. Click [here](https://ant.design/components/form#components-form-demo-customized-form-controls) to see an example | string | `onChange` |
  1982. | validateDebounce | Delay milliseconds to start validation | number | - |
  1983. | validateFirst | Whether stop validate on first rule of error for this field. Will parallel validate when `parallel` configured | boolean \| `parallel` | false |
  1984. | validateStatus | The validation status. If not provided, it will be generated by validation rule. options: `success` `warning` `error` `validating` | string | - |
  1985. | validateTrigger | When to validate the value of children node | string \| string\[] | `onChange` |
  1986. | valuePropName | Props of children node, for example, the prop of Switch or Checkbox is `checked`. This prop is an encapsulation of `getValueProps`, which will be invalid after customizing `getValueProps` | string | `value` |
  1987. | wrapperStyle | The layout for input controls, same as `labelStyle`. You can set `wrapperStyle` on Form which will not affect nest Item. If both exists, use Item first | `ViewStyle` | - |
  1988. The layout of Form.Item is based on List.Item. So it also supports these props of [List.Item](/components/list/#List.Item)
  1989. `arrow` `extra` `thumb`
  1990. After wrapped by `Form.Item` with `name` property, `value`(or other property defined by `valuePropName`) `onChange`(or other property defined by `trigger`) props will be added to form controls, the flow of form data will be handled by Form which will cause:
  1991. 1. You shouldn't use `onChange` on each form control to **collect data**(use `onValuesChange` of Form), but you can still listen to `onChange`.
  1992. 2. You cannot set value for each form control via `value` or `defaultValue` prop, you should set default value with `initialValues` of Form. Note that `initialValues` cannot be updated by `setState` dynamically, you should use `setFieldsValue` in that situation.
  1993. 3. You shouldn't call `setState` manually, please use `form.setFieldsValue` to change value programmatically.
  1994. ### dependencies
  1995. Used when there are dependencies between fields. If a field has the `dependencies` prop, this field will automatically trigger updates and validations when upstream is updated. A common scenario is a user registration form with "password" and "confirm password" fields. The "Confirm Password" validation depends on the "Password" field. After setting `dependencies`, the "Password" field update will re-trigger the validation of "Check Password".
  1996. `dependencies` shouldn't be used together with `shouldUpdate`, since it may result in conflicting update logic.
  1997. ### FeedbackIcons
  1998. `({ status: ValidateStatus, errors: ReactNode, warnings: ReactNode }) => Record<ValidateStatus, ReactNode>`
  1999. ### shouldUpdate
  2000. Form updates only the modified field-related components for performance optimization purposes by incremental update. In most cases, you only need to write code or do validation with the [`dependencies`](#dependencies) property. In some specific cases, such as when a new field option appears with a field value changed, or you just want to keep some area updating by form update, you can modify the update logic of Form.Item via the `shouldUpdate`.
  2001. When `shouldUpdate` is `true`, any Form update will cause the Form.Item to be re-rendered. This is very helpful for custom rendering some areas. It should be noted that the child component should be returned in a function, otherwise `shouldUpdate` won't behave correctly:
  2002. ```jsx
  2003. <Form.Item shouldUpdate>
  2004. {() => {
  2005. return <pre>{JSON.stringify(form.getFieldsValue(), null, 2)}</pre>;
  2006. }}
  2007. </Form.Item>
  2008. ```
  2009. When `shouldUpdate` is a function, it will be called by form values update. Providing original values and current value to compare. This is very helpful for rendering additional fields based on values:
  2010. ```jsx
  2011. <Form.Item shouldUpdate={(prevValues, curValues) => prevValues.additional !== curValues.additional}>
  2012. {() => {
  2013. return (
  2014. <Form.Item name="other">
  2015. <Input />
  2016. </Form.Item>
  2017. );
  2018. }}
  2019. </Form.Item>
  2020. ```
  2021. ### messageVariables
  2022. You can modify the default verification information of Form.Item through `messageVariables`.
  2023. ```jsx
  2024. <Form>
  2025. <Form.Item
  2026. messageVariables={{ another: 'good' }}
  2027. label="user"
  2028. rules={[{ required: true, message: '${another} is required' }]}
  2029. >
  2030. <Input />
  2031. </Form.Item>
  2032. <Form.Item
  2033. messageVariables={{ label: 'good' }}
  2034. label={<span>user</span>}
  2035. rules={[{ required: true, message: '${label} is required' }]}
  2036. >
  2037. <Input />
  2038. </Form.Item>
  2039. </Form>
  2040. ```
  2041. ## Form.List
  2042. Provides array management for fields.
  2043. | Property | Description | Type | Default |
  2044. | --- | --- | --- | --- |
  2045. | children | Render function | (fields: Field\[], operation: { add, remove, move }, meta: { errors }) => React.ReactNode | - |
  2046. | initialValue | Config sub default value. Form `initialValues` get higher priority when conflict | any\[] | - |
  2047. | name | Field name, support array. List is also a field, so it will return all the values by `getFieldsValue`. You can change this logic by [config](#getfieldsvalue) | [NamePath](#namepath) | - |
  2048. | rules | Validate rules, only support customize validator. Should work with [ErrorList](#formerrorlist) | { validator, message }\[] | - |
  2049. ```tsx
  2050. <Form.List>
  2051. {(fields) => (
  2052. <div>
  2053. {fields.map((field) => (
  2054. <Form.Item {...field}>
  2055. <Input />
  2056. </Form.Item>
  2057. ))}
  2058. </div>
  2059. )}
  2060. </Form.List>
  2061. ```
  2062. Note: You should not configure Form.Item `initialValue` under Form.List. It always should be configured by Form.List `initialValue` or Form `initialValues`.
  2063. ## operation
  2064. Some operator functions in render form of Form.List.
  2065. | Property | Description | Type | Default |
  2066. | --- | --- | --- | --- |
  2067. | add | add form item | (defaultValue?: any, insertIndex?: number) => void | insertIndex |
  2068. | move | move form item | (from: number, to: number) => void | - |
  2069. | remove | remove form item | (index: number \| number\[]) => void | number\[] |
  2070. ## Form.ErrorList
  2071. Show error messages, should only work with `rules` of Form.List. See [example](https://ant.design/components/form#components-form-demo-dynamic-form-item).
  2072. | Property | Description | Type | Default |
  2073. | -------- | ----------- | ------------ | ------- |
  2074. | errors | Error list | ReactNode\[] | - |
  2075. | styles | Semantic DOM style | [ValidateStatusStyle](#validatestatusstyle-interface) | - |
  2076. ## Form.Provider
  2077. Provide linkage between forms. If a sub form with `name` prop update, it will auto trigger Provider related events. See [example](https://ant.design/components/form#components-form-demo-form-context).
  2078. | Property | Description | Type | Default |
  2079. | --- | --- | --- | --- |
  2080. | onFormChange | Triggered when a sub form field updates | function(formName: string, info: { changedFields, forms }) | - |
  2081. | onFormFinish | Triggered when a sub form submits | function(formName: string, info: { values, forms }) | - |
  2082. ```jsx
  2083. <Form.Provider
  2084. onFormFinish={(name) => {
  2085. if (name === 'form1') {
  2086. // Do something...
  2087. }
  2088. }}
  2089. >
  2090. <Form name="form1">...</Form>
  2091. <Form name="form2">...</Form>
  2092. </Form.Provider>
  2093. ```
  2094. ### FormInstance
  2095. | Name | Description | Type |
  2096. | --- | --- | --- |
  2097. | getFieldError | Get the error messages by the field name | (name: [NamePath](#namepath)) => string\[] |
  2098. | getFieldInstance | Get field instance | (name: [NamePath](#namepath)) => any |
  2099. | getFieldsError | Get the error messages by the fields name. Return as an array | (nameList?: [NamePath](#namepath)\[]) => FieldError\[] |
  2100. | getFieldsValue | Get values by a set of field names. Return according to the corresponding structure. Default return mounted field value, but you can use `getFieldsValue(true)` to get all values | [GetFieldsValue](#getfieldsvalue) |
  2101. | getFieldValue | Get the value by the field name | (name: [NamePath](#namepath)) => any |
  2102. | isFieldsTouched | Check if fields have been operated. Check if all fields is touched when `allTouched` is `true` | (nameList?: [NamePath](#namepath)\[], allTouched?: boolean) => boolean |
  2103. | isFieldTouched | Check if a field has been operated | (name: [NamePath](#namepath)) => boolean |
  2104. | isFieldValidating | Check field if is in validating | (name: [NamePath](#namepath)) => boolean |
  2105. | resetFields | Reset fields to `initialValues` | (fields?: [NamePath](#namepath)\[]) => void |
  2106. | scrollToField | Scroll to field position | (name: [NamePath](#namepath), options: \[[ScrollOptions](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options)]) => void |
  2107. | setFields | Set fields status | (fields: [FieldData](#fielddata)\[]) => void |
  2108. | setFieldValue | Set fields value(Will directly pass to form store and **reset validation message**. If you do not want to modify passed object, please clone first) | (name: [NamePath](#namepath), value: any) => void |
  2109. | setFieldsValue | Set fields value(Will directly pass to form store and **reset validation message**. If you do not want to modify passed object, please clone first). Use `setFieldValue` instead if you want to only config single value in Form.List | (values) => void |
  2110. | submit | Submit the form. It's same as click `submit` button | () => void |
  2111. | validateFields | Validate fields. Use `recursive` to validate all the field in the path | (nameList?: [NamePath](#namepath)\[], config?: [ValidateConfig](#validateFields)) => Promise |
  2112. #### validateFields
  2113. ```tsx
  2114. export interface ValidateConfig {
  2115. // Only validate content and not show error message on UI.
  2116. validateOnly?: boolean;
  2117. // Recursively validate the provided `nameList` and its sub-paths.
  2118. recursive?: boolean;
  2119. // Validate dirty fields (touched + validated).
  2120. // It's useful to validate fields only when they are touched or validated.
  2121. dirty?: boolean;
  2122. }
  2123. ```
  2124. return sample:
  2125. ```jsx
  2126. validateFields()
  2127. .then((values) => {
  2128. /*
  2129. values:
  2130. {
  2131. username: 'username',
  2132. password: 'password',
  2133. }
  2134. */
  2135. })
  2136. .catch((errorInfo) => {
  2137. /*
  2138. errorInfo:
  2139. {
  2140. values: {
  2141. username: 'username',
  2142. password: 'password',
  2143. },
  2144. errorFields: [
  2145. { name: ['password'], errors: ['Please input your Password!'] },
  2146. ],
  2147. outOfDate: false,
  2148. }
  2149. */
  2150. });
  2151. ```
  2152. ### FormItemStyle interface
  2153. ```typescript
  2154. interface FormItemStyle extends ListItemStyle {
  2155. // label prop
  2156. formItemLabel: ViewStyle // { minWidth: 65 }
  2157. formItemLabelText: ViewStyle | TextStyle
  2158. // children style
  2159. formItemControl: ViewStyle
  2160. // required={true}
  2161. asterisk: TextStyle
  2162. // requiredMark="optional"
  2163. optional: TextStyle
  2164. }
  2165. ```
  2166. ### ValidateStatusStyle interface
  2167. when set `validateStatus` prop
  2168. ```typescript
  2169. interface ValidateStatusStyle {
  2170. error: TextStyle
  2171. warning: TextStyle
  2172. success: TextStyle
  2173. validating: TextStyle
  2174. feedbackIcon: ViewStyle
  2175. }
  2176. ```
  2177. ## Hooks
  2178. ### Form.useForm
  2179. `type Form.useForm = (): [FormInstance]`
  2180. Create Form instance to maintain data store.
  2181. ### Form.useFormInstance
  2182. `type Form.useFormInstance = (): FormInstance`
  2183. Get current context form instance to avoid pass as props between components:
  2184. ```tsx
  2185. const Sub = () => {
  2186. const form = Form.useFormInstance();
  2187. return <Button onClick={() => form.setFieldsValue({})} />;
  2188. };
  2189. export default () => {
  2190. const [form] = Form.useForm();
  2191. return (
  2192. <Form form={form}>
  2193. <Sub />
  2194. </Form>
  2195. );
  2196. };
  2197. ```
  2198. ### Form.useWatch
  2199. `type Form.useWatch = (namePath: NamePath | (selector: (values: Store) => any), formInstance?: FormInstance | WatchOptions): Value`
  2200. Watch the value of a field. You can use this to interact with other hooks like `useSWR` to reduce development costs:
  2201. ```tsx
  2202. const Demo = () => {
  2203. const [form] = Form.useForm();
  2204. const userName = Form.useWatch('username', form);
  2205. const { data: options } = useSWR(`/api/user/${userName}`, fetcher);
  2206. return (
  2207. <Form form={form}>
  2208. <Form.Item name="username">
  2209. <AutoComplete options={options} />
  2210. </Form.Item>
  2211. </Form>
  2212. );
  2213. };
  2214. ```
  2215. If your component is wrapped by `Form.Item`, you can omit the second argument, `Form.useWatch` will find the nearest `FormInstance` automatically.
  2216. By default `useWatch` only watches the registered field. If you want to watch the unregistered field, please use `preserve`:
  2217. ```tsx
  2218. const Demo = () => {
  2219. const [form] = Form.useForm();
  2220. const age = Form.useWatch('age', { form, preserve: true });
  2221. console.log(age);
  2222. return (
  2223. <div>
  2224. <Button onClick={() => form.setFieldValue('age', 2)}>Update</Button>
  2225. <Form form={form}>
  2226. <Form.Item name="name">
  2227. <Input />
  2228. </Form.Item>
  2229. </Form>
  2230. </div>
  2231. );
  2232. };
  2233. ```
  2234. ### Form.Item.useStatus
  2235. `type Form.Item.useStatus = (): { status: ValidateStatus | undefined, errors: ReactNode[], warnings: ReactNode[] }`
  2236. Could be used to get validate status of Form.Item. If this hook is not used under Form.Item, `status` would be `undefined`. `error` and `warnings` could be used to get error messages and warning messages of Form.Item:
  2237. ```tsx
  2238. const CustomInput = ({ value, onChange }) => {
  2239. const { status, errors } = Form.Item.useStatus();
  2240. return (
  2241. <input
  2242. value={value}
  2243. onChange={onChange}
  2244. className={`custom-input-${status}`}
  2245. placeholder={(errors.length && errors[0]) || ''}
  2246. />
  2247. );
  2248. };
  2249. export default () => (
  2250. <Form>
  2251. <Form.Item name="username">
  2252. <CustomInput />
  2253. </Form.Item>
  2254. </Form>
  2255. );
  2256. ```
  2257. #### Difference between other data fetching method
  2258. Form only update the Field which changed to avoid full refresh perf issue. Thus you can not get real time value with `getFieldsValue` in render. And `useWatch` will rerender current component to sync with latest value. You can also use Field renderProps to get better performance if only want to do conditional render. If component no need care field value change, you can use `onValuesChange` to give to parent component to avoid current one rerender.
  2259. ### Interface
  2260. #### NamePath
  2261. `string | number | (string | number)[]`
  2262. #### GetFieldsValue
  2263. `getFieldsValue` provides overloaded methods:
  2264. ##### getFieldsValue(nameList?: true | [NamePath](#namepath)\[], filterFunc?: FilterFunc)
  2265. When `nameList` is empty, return all registered fields, including values of List (even if List has no Item children).
  2266. When `nameList` is `true`, return all values in store, including unregistered fields. For example, if you set the value of an unregistered Item through `setFieldsValue`, you can also get all values through `true`.
  2267. When `nameList` is an array, return the value of the specified path. Note that `nameList` is a nested array. For example, you need the value of a certain path as follows:
  2268. ```tsx
  2269. // Single path
  2270. form.getFieldsValue([['user', 'age']]);
  2271. // multiple path
  2272. form.getFieldsValue([
  2273. ['user', 'age'],
  2274. ['preset', 'account'],
  2275. ]);
  2276. ```
  2277. ##### getFieldsValue({ strict?: boolean, filter?: FilterFunc })
  2278. Accept configuration parameters. When `strict` is `true`, only the value of Item will be matched. For example, in `{ list: [{ bamboo: 1, little: 2 }] }`, if List is only bound to the `bamboo` field, then `getFieldsValue({ strict: true })` will only get `{ list: [{ bamboo: 1 }] }`.
  2279. #### FilterFunc
  2280. To filter certain field values, `meta` will provide information related to the fields. For example, it can be used to retrieve values that have only been modified by the user, and so on.
  2281. ```tsx
  2282. type FilterFunc = (meta: { touched: boolean; validating: boolean }) => boolean;
  2283. ```
  2284. #### FieldData
  2285. | Name | Description | Type |
  2286. | ---------- | ------------------------ | ------------------------ |
  2287. | errors | Error messages | string\[] |
  2288. | warnings | Warning messages | string\[] |
  2289. | name | Field name path | [NamePath](#namepath)\[] |
  2290. | touched | Whether is operated | boolean |
  2291. | validating | Whether is in validating | boolean |
  2292. | value | Field value | any |
  2293. #### Rule
  2294. Rule supports a config object, or a function returning config object:
  2295. ```tsx
  2296. type Rule = RuleConfig | ((form: FormInstance) => RuleConfig);
  2297. ```
  2298. | Name | Description | Type |
  2299. | --- | --- | --- |
  2300. | defaultField | Validate rule for all array elements, valid when `type` is `array` | [rule](#rule) |
  2301. | enum | Match enum value. You need to set `type` to `enum` to enable this | any\[] |
  2302. | fields | Validate rule for child elements, valid when `type` is `array` or `object` | Record&lt;string, [rule](#rule)> |
  2303. | len | Length of string, number, array | number |
  2304. | max | `type` required: max length of `string`, `number`, `array` | number |
  2305. | message | Error message. Will auto generate by [template](#validatemessages) if not provided | string |
  2306. | min | `type` required: min length of `string`, `number`, `array` | number |
  2307. | pattern | Regex pattern | RegExp |
  2308. | required | Required field | boolean |
  2309. | transform | Transform value to the rule before validation | (value) => any |
  2310. | type | Normally `string` \|`number` \|`boolean` \|`url` \| `email`. More type to ref [here](https://github.com/yiminghe/async-validator#type) | string |
  2311. | validateTrigger | Set validate trigger event. Must be the sub set of `validateTrigger` in Form.Item | string \| string\[] |
  2312. | validator | Customize validation rule. Accept Promise as return. See [example](https://ant.design/components/form#components-form-demo-register) | ([rule](#rule), value) => Promise |
  2313. | warningOnly | Warning only. Not block form submit | boolean |
  2314. | whitespace | Failed if only has whitespace, only work with `type: 'string'` rule | boolean |
  2315. #### WatchOptions
  2316. | Name | Description | Type | Default |
  2317. | --- | --- | --- | --- |
  2318. | form | Form instance | FormInstance | Current form in context |
  2319. | preserve | Whether to watch the field which has no matched `Form.Item` | boolean | false |
  2320. ## FAQ
  2321. ### Why can't Switch、Checkbox、Radio bind data?
  2322. Form.Item default bind value to `value` prop, but Switch or Checkbox value prop is `checked`. You can use `valuePropName` to change bind value prop.
  2323. ```tsx | pure
  2324. <Form.Item name="fieldA" valuePropName="checked">
  2325. <Switch />
  2326. </Form.Item>
  2327. ```
  2328. ### How does Form.Item work with Picker / DatePicker?
  2329. When Picker's `children` is `List.Item`, it can be used directly.
  2330. <br/>Note: Form.Item need `noStyle` prop
  2331. ```tsx
  2332. <Form.Item name="address" noStyle>
  2333. <Picker data={data} cols={3}>
  2334. <List.Item>地址</List.Item>
  2335. </Picker>
  2336. </Form.Item>
  2337. ```
  2338. However, we recommend the composition layout of `Form.Item` and `Input`, so how to use it when `children` is not `List.Item`?
  2339. <br/>
  2340. When `children` is a **function**, the `toggle` parameter will be provided to control the display/hide of Picker.
  2341. ```tsx
  2342. <Form.Item label="地址" name="address">
  2343. <Picker data={data} cols={3} >
  2344. {({ extra, value, toggle }: any) => (
  2345. <Input
  2346. value={value?.length ? extra : undefined}
  2347. onFocus={toggle}
  2348. placeholder="省/市/区"
  2349. />
  2350. )}
  2351. </Picker>
  2352. </Form.Item>
  2353. ```
  2354. Secondly, you can use `ref`
  2355. ```tsx
  2356. const pickerRef = useRef();
  2357. <Form.Item label="地址" name="address" onPress={()=>pickerRef.current?.toggle()}>
  2358. <Picker data={data} cols={3} ref={pickerRef}>
  2359. <Input placeholder="省/市/区"/>
  2360. </Picker>
  2361. </Form.Item>
  2362. ```
  2363. ### Is there any more reference documentation?
  2364. https://ant.design/components/form-cn
  2365. ---
  2366. ## Grid
  2367. Source: https://rn.mobile.ant.design/components/grid.md
  2368. # Grid
  2369. We divided the design area into a number of aliquots in horizontal and vertical.
  2370. ### Rules
  2371. - The contents of the blocks should have the same type. eg: they are all pictures or icons with text.
  2372. ## Examples
  2373. ```tsx
  2374. import { Grid } from '@ant-design/react-native'
  2375. import React from 'react'
  2376. import { ScrollView, Text, View } from 'react-native'
  2377. const data = Array.from(new Array(9)).map((_val, i) => ({
  2378. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  2379. text: `Name${i}`,
  2380. }))
  2381. export default class BasicGridExample extends React.Component<any, any> {
  2382. render() {
  2383. return (
  2384. <ScrollView>
  2385. <View style={[{ margin: 10 }]}>
  2386. <Text>Simple</Text>
  2387. </View>
  2388. <View style={[{ padding: 10 }]}>
  2389. <Grid data={data} hasLine={false} />
  2390. </View>
  2391. <View style={[{ margin: 10 }]}>
  2392. <Text>Carousel</Text>
  2393. </View>
  2394. <Grid
  2395. data={data}
  2396. columnNum={3}
  2397. isCarousel
  2398. carouselProps={{
  2399. style: {
  2400. width: '100%',
  2401. height: 320,
  2402. },
  2403. }}
  2404. onPress={(_el: any, index: any) => alert(index)}
  2405. />
  2406. <View style={[{ margin: 10 }]}>
  2407. <Text>Custom GridCell Style</Text>
  2408. </View>
  2409. <Grid
  2410. data={data}
  2411. columnNum={3}
  2412. itemStyle={{ height: 150, backgroundColor: '#ffff00' }}
  2413. />
  2414. </ScrollView>
  2415. )
  2416. }
  2417. }
  2418. ```
  2419. ## API
  2420. | Properties | Description | Type | Default |
  2421. | -------------- | ------------------------------------------------------------- | --------------------------------- | ----------- |
  2422. | data | data record array to be rendered | `Array<{icon, text}>` | [] |
  2423. | onPress | Handler to be called when the user taps the grid | (el: Object, index: number): void | - |
  2424. | columnNum | the number of columns | number | `4` |
  2425. | hasLine | whether to show border | boolean | `true` |
  2426. | isCarousel | whether to be played as a Carousel | boolean | `false` |
  2427. | carouselProps | Carousel Props | CarouselProps | `{}` |
  2428. | carouselMaxRow | the max number of rows to be showed each page of the Carousel | number | `2` |
  2429. | renderItem | custom function to create each grid item | (el, index) => React.Node | - |
  2430. | itemStyle | Custom GridCell Style | object | {} |
  2431. When `isCarousel = true`, the APIs of [carousel](https://mobile.ant.design/components/carousel) also can be delivered.
  2432. ---
  2433. ## Icon
  2434. Source: https://rn.mobile.ant.design/components/icon.md
  2435. # Icon
  2436. ## How to Use
  2437. ### 安装依赖
  2438. ```bash
  2439. npm install @ant-design/icons-react-native@latest
  2440. ```
  2441. ### Linking
  2442. - Add assets to your `react-native.config.js` ( If not exist, please create in project’s root directory )
  2443. ```js
  2444. module.exports = {
  2445. assets: ['node_modules/@ant-design/icons-react-native/fonts'],
  2446. };
  2447. ```
  2448. - Run the [`react-native-asset`](https://github.com/unimonkiez/react-native-asset)'s command and linking + unlinking is automatic
  2449. ```bash
  2450. npx react-native-asset
  2451. ```
  2452. will copy fonts to `ios` and `android` assets folder.
  2453. - If you have an Expo managed project, skip the previous two steps and use [expo-font](https://docs.expo.dev/versions/latest/sdk/font/) to load the font directly:
  2454. ```jsx
  2455. import { useFonts } from 'expo-font';
  2456. const [fontsLoaded] = useFonts({
  2457. antoutline: require('@ant-design/icons-react-native/fonts/antoutline.ttf'),
  2458. })
  2459. ```
  2460. ## Examples
  2461. ```tsx
  2462. import {
  2463. outlineGlyphMap,
  2464. OutlineGlyphMapType,
  2465. } from '@ant-design/icons-react-native/lib/outline'
  2466. import { Grid, Icon, SearchBar, Toast } from '@ant-design/react-native'
  2467. import React from 'react'
  2468. import { ScrollView } from 'react-native'
  2469. const data = Object.keys(outlineGlyphMap).map((item: OutlineGlyphMapType) => ({
  2470. icon: <Icon name={item} />,
  2471. text: item,
  2472. }))
  2473. export default class IConDemo extends React.Component<any, any> {
  2474. state = {
  2475. data,
  2476. }
  2477. handlePress = (dataItem: { icon?: any; text?: string }) => {
  2478. Toast.show(`<Icon name="${dataItem.text}" />`)
  2479. }
  2480. render() {
  2481. return (
  2482. <ScrollView>
  2483. <SearchBar
  2484. placeholder="Search by icon name"
  2485. onChange={(text) => {
  2486. this.setState(() => ({
  2487. data: data.filter((d) => d.text.match(new RegExp(text, 'gi'))),
  2488. }))
  2489. }}
  2490. />
  2491. <Grid
  2492. data={this.state.data}
  2493. columnNum={3}
  2494. hasLine={false}
  2495. onPress={this.handlePress}
  2496. />
  2497. </ScrollView>
  2498. )
  2499. }
  2500. }
  2501. export const title = 'Icon'
  2502. export const description = 'Icon Example'
  2503. ```
  2504. ## API
  2505. | Properties | Description | Type | Default |
  2506. | ---------- | ------------------- | ---------------------------------- | ------- |
  2507. | name | `OutlineGlyphMapType` | string |
  2508. | size | icon size | 'xxs'/'xs'/'sm'/'md'/'lg' / number | `md` |
  2509. | color | icon color | Color | '#000' |
  2510. - Tips1: Clicking the icon in the demo will automatically copy the code to the `<Icon />`.
  2511. - Tips2: By default, Icon uses the `outline` icon in `ant-design-icons`
  2512. ---
  2513. ## Input
  2514. Source: https://rn.mobile.ant.design/components/input.md
  2515. # Input
  2516. Entering content through the keyboard is the most basic form field wrapper.
  2517. ### Rule
  2518. - It is generally used in form pages to collect information, and provides two types of text boxes and text-area boxes.
  2519. - The Input component is layout-independent. It can be used with the `List` component for quick layout; it also has built-in linkage interaction with the `Form` component.
  2520. ## Examples
  2521. ```tsx
  2522. import { Input, List } from '@ant-design/react-native'
  2523. import React from 'react'
  2524. import { KeyboardAvoidingView, Platform, ScrollView } from 'react-native'
  2525. export default function InputExample() {
  2526. const [value, setValue] = React.useState('')
  2527. return (
  2528. <KeyboardAvoidingView
  2529. behavior="padding"
  2530. keyboardVerticalOffset={Platform.OS === 'ios' ? 100 : undefined}>
  2531. <ScrollView keyboardShouldPersistTaps="handled">
  2532. <List renderHeader="基本用法">
  2533. <List.Item>
  2534. <Input placeholder="请输入内容" />
  2535. </List.Item>
  2536. </List>
  2537. <List renderHeader="受控模式">
  2538. <List.Item>
  2539. <Input
  2540. placeholder="请输入内容"
  2541. value={value}
  2542. onChangeText={setValue}
  2543. />
  2544. </List.Item>
  2545. </List>
  2546. <List renderHeader="带清除按钮">
  2547. <List.Item>
  2548. <Input allowClear placeholder="allowClear" />
  2549. </List.Item>
  2550. </List>
  2551. <List renderHeader="前缀和后缀">
  2552. <List.Item>
  2553. <Input prefix="前缀" suffix="后缀" placeholder="prefix / suffix" />
  2554. </List.Item>
  2555. </List>
  2556. <List renderHeader="带字数提示">
  2557. <List.Item>
  2558. <Input showCount placeholder="showCount" />
  2559. </List.Item>
  2560. <List.Item>
  2561. <Input
  2562. maxLength={5}
  2563. showCount={{
  2564. formatter: ({ count, maxLength }) => `${count}/${maxLength}`,
  2565. }}
  2566. placeholder="showCount.formatter"
  2567. />
  2568. </List.Item>
  2569. </List>
  2570. <List renderHeader="TextArea">
  2571. <List.Item>
  2572. <Input.TextArea
  2573. rows={4}
  2574. maxLength={100}
  2575. showCount
  2576. allowClear
  2577. placeholder="固定行数 row={4}"
  2578. />
  2579. </List.Item>
  2580. </List>
  2581. <List renderHeader="根据内容自动调整高度">
  2582. <List.Item>
  2583. <Input.TextArea autoSize placeholder="autoSize={true}" />
  2584. </List.Item>
  2585. <List.Item>
  2586. <Input.TextArea
  2587. autoSize={{ minRows: 2, maxRows: 6 }}
  2588. placeholder="autoSize={{ minRows: 2, maxRows: 6 }}"
  2589. />
  2590. </List.Item>
  2591. </List>
  2592. </ScrollView>
  2593. </KeyboardAvoidingView>
  2594. )
  2595. }
  2596. ```
  2597. ## API
  2598. ### Input
  2599. | Properties | Description | Type | Default |
  2600. | --- | --- | --- | --- |
  2601. | allowClear | If allow to remove input content with clear icon | `boolean` \| `{ clearIcon: ReactNode }` | - |
  2602. | defaultValue | The initial input content | string | - |
  2603. | disabled | Whether the input is disabled | boolean | false |
  2604. | maxLength | The maximum number of characters in Input | number | - |
  2605. | prefix | The prefix icon for the Input | ReactNode | - |
  2606. | showCount | Whether to show character count | `boolean` \| `{ formatter: (info: { value: string, count: number, maxLength?: number }) => ReactNode }` | false |
  2607. | status | Set validation status | 'error' \| 'warning' | - |
  2608. | inputStyle | TextInput style | `StyleProp<TextStyle>` | - |
  2609. | style | Container style | `StyleProp<ViewStyle>` | - |
  2610. | styles | Semantic DOM style | [InputStyle](#inputstyle-interface) | - |
  2611. | suffix | The suffix icon for the Input | ReactNode | - |
  2612. | type | Declare the Input type, the same as the native [keyboardType](http://facebook.github.io/react-native/docs/textinput.html#keyboardtype) attribute | 'text' \| 'number' \| 'password' \| KeyboardTypeOptions | `text` |
  2613. | value | The input content value | string | - |
  2614. | onChange | Callback when user input, extra return `e.target.value` | `(e: NativeSyntheticEvent<TextInputChangeEventData>) => void;` | - |
  2615. The rest of the props of Input are exactly the same as the react-native [TextInput](http://facebook.github.io/react-native/docs/textinput.html).
  2616. ### Input.TextArea
  2617. Same as Input, and more:
  2618. | Property | Description | Type | Default |
  2619. | --- | --- | --- | --- |
  2620. | autoSize | Height auto size feature, can be set to `true` \| `false` or an object `{ minRows: 2, maxRows: 6 }` | boolean \| object | false |
  2621. | rows | sets the number of lines for a textarea. Prioritize`autoSize` | number | 2 |
  2622. | styles | Semantic DOM style | [InputStyle](#inputstyle-interface) | - |
  2623. ### InputStyle interface
  2624. ```typescript
  2625. interface InputStyle {
  2626. container: ViewStyle // Same as `style` prop
  2627. input: ViewStyle // Same as `inputStyle` prop
  2628. clearIcon: ViewStyle
  2629. prefix: ViewStyle | TextStyle
  2630. showCount: TextStyle
  2631. suffix: ViewStyle | TextStyle
  2632. warning: TextStyle
  2633. error: TextStyle
  2634. }
  2635. ```
  2636. ## Ref
  2637. Ref to [TextInput](http://facebook.github.io/react-native/docs/textinput.html)
  2638. ## FAQ
  2639. ## When setting `allowClear` on the Android platform, why does it not work when I click clearIcon?
  2640. In Android, clearIcon will only appear when you are in editing state (`focus`).
  2641. <br/>When this component is wrapped by `ScrollView`, set the `keyboardShouldPersistTaps` property to `handled` or `always`, the icon will respond correctly to the click event
  2642. ```jsx
  2643. <ScrollView keyboardShouldPersistTaps="always">
  2644. ...
  2645. </ScrollView>
  2646. ```
  2647. ### Why Input in control can make `value` exceed `maxLength`?
  2648. When in control, component should show as what it set to avoid submit value not align with store value in Form.
  2649. ---
  2650. ## InputItem
  2651. Source: https://rn.mobile.ant.design/components/input-item.md
  2652. # InputItem
  2653. > This package has been deprecated in `5.2.1`, recommend [components/Input](/components/input)
  2654. A foundational component for inputting text into the app via a keyboard.
  2655. ### Rule
  2656. - Support text input via keyboard or clipboard.
  2657. - The cursor can be moved horizontally.
  2658. - Handle text with a specific format, eg: hide password.
  2659. ## Examples
  2660. ```tsx
  2661. import { Button, InputItem, List } from '@ant-design/react-native'
  2662. import React from 'react'
  2663. import { ScrollView, Text } from 'react-native'
  2664. declare var jest: any
  2665. export default class BasicInputItemExample extends React.Component<any, any> {
  2666. inputRef: any
  2667. constructor(props: any) {
  2668. super(props)
  2669. this.state = {
  2670. value: '',
  2671. value1: '',
  2672. value2: '',
  2673. value3: '',
  2674. value4: '',
  2675. labelnum1: '',
  2676. labelnum2: '',
  2677. labelnum3: '',
  2678. text: '',
  2679. bankCard: '',
  2680. phone: '',
  2681. password: '',
  2682. number: '',
  2683. }
  2684. }
  2685. render() {
  2686. return (
  2687. <ScrollView
  2688. style={{ flex: 1 }}
  2689. automaticallyAdjustContentInsets={false}
  2690. showsHorizontalScrollIndicator={false}
  2691. showsVerticalScrollIndicator={false}
  2692. keyboardShouldPersistTaps={'handled'}>
  2693. <List renderHeader={'基本'}>
  2694. <InputItem
  2695. clear
  2696. error
  2697. value={this.state.value}
  2698. onChange={(value: any) => {
  2699. this.setState({
  2700. value,
  2701. })
  2702. }}
  2703. extra="元"
  2704. placeholder="有标签">
  2705. 输入框
  2706. </InputItem>
  2707. <InputItem
  2708. clear
  2709. value="不可编辑"
  2710. onChange={(value: any) => {
  2711. this.setState({
  2712. value,
  2713. })
  2714. }}
  2715. extra={<Text>元</Text>}
  2716. placeholder="不可编辑"
  2717. editable={false}>
  2718. 输入框
  2719. </InputItem>
  2720. <InputItem
  2721. clear
  2722. value="disabled"
  2723. onChange={(value: any) => {
  2724. this.setState({
  2725. value,
  2726. })
  2727. }}
  2728. extra={<Text>元</Text>}
  2729. placeholder="disabled"
  2730. disabled>
  2731. 输入框
  2732. </InputItem>
  2733. <InputItem
  2734. clear
  2735. value={this.state.value1}
  2736. onChange={(value: any) => {
  2737. this.setState({
  2738. value1: value,
  2739. })
  2740. }}
  2741. placeholder="无标签"
  2742. />
  2743. <InputItem
  2744. defaultValue="xx"
  2745. clear
  2746. placeholder="自动获取光标"
  2747. autoFocus={
  2748. /* TODO: https://github.com/facebook/jest/issues/3707 */ typeof jest ===
  2749. 'undefined'
  2750. }>
  2751. 标题
  2752. </InputItem>
  2753. <InputItem
  2754. clear
  2755. placeholder="点击下方按钮该输入框会获取光标"
  2756. ref={(el: any) => (this.inputRef = el)}>
  2757. 标题
  2758. </InputItem>
  2759. <List.Item>
  2760. <Button
  2761. onPress={() => {
  2762. this.inputRef.focus()
  2763. }}
  2764. type="primary">
  2765. 点击获取光标
  2766. </Button>
  2767. </List.Item>
  2768. </List>
  2769. <List renderHeader={'固定标签字数'}>
  2770. <InputItem
  2771. clear
  2772. value={this.state.labelnum1}
  2773. onChange={(value: any) => {
  2774. this.setState({
  2775. labelnum1: value,
  2776. })
  2777. }}
  2778. labelNumber={2}
  2779. placeholder="两个字标签">
  2780. 姓名
  2781. </InputItem>
  2782. <InputItem
  2783. clear
  2784. value={this.state.labelnum2}
  2785. onChange={(value: any) => {
  2786. this.setState({
  2787. labelnum2: value,
  2788. })
  2789. }}
  2790. labelNumber={3}
  2791. placeholder="三个字标签">
  2792. 校验码
  2793. </InputItem>
  2794. <InputItem
  2795. clear
  2796. value={this.state.labelnum3}
  2797. onChange={(value: any) => {
  2798. this.setState({
  2799. labelnum3: value,
  2800. })
  2801. }}
  2802. labelNumber={4}
  2803. placeholder="四个字标签(默认)">
  2804. 四字标签
  2805. </InputItem>
  2806. </List>
  2807. <List renderHeader={'格式'}>
  2808. <InputItem
  2809. clear
  2810. error
  2811. value={this.state.text}
  2812. onChange={(value: any) => {
  2813. this.setState({
  2814. text: value,
  2815. })
  2816. }}
  2817. placeholder="text">
  2818. 文本输入
  2819. </InputItem>
  2820. <InputItem
  2821. clear
  2822. type="bankCard"
  2823. value={this.state.bankcard}
  2824. onChange={(value: any) => {
  2825. this.setState({
  2826. bankcard: value,
  2827. })
  2828. }}
  2829. placeholder="bankCard">
  2830. 银行卡
  2831. </InputItem>
  2832. <InputItem
  2833. clear
  2834. type="phone"
  2835. value={this.state.phone}
  2836. onChange={(value: any) => {
  2837. this.setState({
  2838. phone: value,
  2839. })
  2840. }}
  2841. placeholder="phone">
  2842. 手机号
  2843. </InputItem>
  2844. <InputItem
  2845. clear
  2846. type="password"
  2847. value={this.state.password}
  2848. onChange={(value: any) => {
  2849. this.setState({
  2850. password: value,
  2851. })
  2852. }}
  2853. placeholder="password">
  2854. 密码
  2855. </InputItem>
  2856. <InputItem
  2857. clear
  2858. type="number"
  2859. value={this.state.number}
  2860. onChange={(value: any) => {
  2861. this.setState({
  2862. number: value,
  2863. })
  2864. }}
  2865. placeholder="number">
  2866. 数字
  2867. </InputItem>
  2868. </List>
  2869. </ScrollView>
  2870. )
  2871. }
  2872. }
  2873. ```
  2874. ## API
  2875. **`InputItem` must wrapped by a [List](https://mobile.ant.design/components/list)**
  2876. Properties | Description | Type | Default
  2877. -----------|------------|------|--------
  2878. | type | can be `bankCard`; `phone`(which the maxLength is 11 and setting will be ignored); `password`; `number`(in order to evoke the 'numeric keyboard with decimal', this type is not a native number, but `<input type="text" pattern="[0-9]*"/>`); `digit`(represent the native type number); As well as other standard html input type values. | String | `text` |
  2879. | value | the value of input (see [react doc](https://facebook.github.io/react/docs/forms.html) for more information about controled component) | String | |
  2880. | defaultValue | provides an initial value that will change when the user starts typing. | String | - |
  2881. | placeholder | the string that will be rendered before text input has been entered. | String | '' |
  2882. | editable | whether is editable | bool | true |
  2883. | disabled | whether is disabled | bool | true |
  2884. | clear | whether to display clear(it takes effect only `editable` is `true` and `disabled` is `false` has been set) | bool | false |
  2885. | maxLength | limits the maximum number of characters that can be entered | number | |
  2886. | onChange | callback that is called when the text input's text changes | (val: string): void | - |
  2887. | onBlur | callback that is called when the text input is blurred | (val: string): void | - |
  2888. | onFocus | callback that is called when the text input is focused | (val: string): void | - |
  2889. | error | whether to display error | bool | false |
  2890. | onErrorClick | callback that is called when the error icon is clicked | (e: Object): void | |
  2891. | extra | the right content of `InputItem` | string or node | '' |
  2892. | onExtraClick | callback that is called when the extra content is clicked | (e: Object): void | |
  2893. | onVirtualKeyboardConfirm | callback that is called when "confirm" button of virtual keyboard is clicked | (val: string): void | |
  2894. | labelNumber | number of label text, valid value is 2 to 7 | number | `5` |
  2895. | locale | 国际化,可覆盖全局`[LocaleProvider](https://mobile.ant.design/components/locale-provider)`的配置, when`type`is`money`,can cunstom the keyboard confirm item's label | Object: { confirmLabel } | 无 |
  2896. | last | If it is the last item, the `borderBottom` will be removed, the default has `borderBottom` | bool | false |
  2897. > More available react-native `InputItem` API can be found at [react-native TextInput](http://facebook.github.io/react-native/docs/textinput.html)
  2898. > Note: `InputItem` does not support negative number if `type` is text, you can use `type=text` to do that.
  2899. ## InputItem Instance methods
  2900. Property | Description | Type | Default
  2901. ----|-----|------|------
  2902. | focus | Force focus back onto the input node | (): void | - |
  2903. ---
  2904. ## List
  2905. Source: https://rn.mobile.ant.design/components/list.md
  2906. # List
  2907. A single and continuous block content is vertically arranged to display current contents, status and available operations. eg:Contact List.
  2908. In case you need an infinite scroll list - consider using [ListView](https://mobile.ant.design/components/list-view/) component.
  2909. ### Rule
  2910. - Generally `List` consists of main infomation, main operations, secondary infomation and secondary operations.
  2911. - The main infomation and main operations are placed on the left side of list, and secondary infomation and secondary operations are placed on the right side.
  2912. ## Examples
  2913. ```tsx
  2914. import { List } from '@ant-design/react-native'
  2915. import React from 'react'
  2916. import { Image, ScrollView, View } from 'react-native'
  2917. const Item = List.Item
  2918. const Brief = Item.Brief
  2919. export default class BasicListExample extends React.Component<any, any> {
  2920. render() {
  2921. return (
  2922. <ScrollView
  2923. style={{ flex: 1, backgroundColor: '#f5f5f9' }}
  2924. automaticallyAdjustContentInsets={false}
  2925. showsHorizontalScrollIndicator={false}
  2926. showsVerticalScrollIndicator={false}>
  2927. <List renderHeader={'basic'}>
  2928. <Item data-seed="logId">
  2929. 标题文字点击无反馈,文字超长则隐藏,文字超长则隐藏
  2930. </Item>
  2931. <Item wrap>
  2932. 文字超长折行文字超长折行文字超长折行文字超长折行文字超长折行
  2933. </Item>
  2934. <Item disabled extra="箭头向右" arrow="horizontal" onPress={() => {}}>
  2935. 标题文字
  2936. </Item>
  2937. <Item extra="箭头向下" arrow="down" onPress={() => {}}>
  2938. 标题文字
  2939. </Item>
  2940. <Item extra="箭头向上" arrow="up" onPress={() => {}}>
  2941. 标题文字
  2942. </Item>
  2943. <Item extra="没有箭头" arrow="empty">
  2944. 标题文字
  2945. </Item>
  2946. <Item
  2947. extra={
  2948. <View>
  2949. 内容内容
  2950. <Brief style={{ textAlign: 'right' }}>辅助文字内容</Brief>
  2951. </View>
  2952. }
  2953. multipleLine>
  2954. 垂直居中对齐
  2955. </Item>
  2956. <Item extra="内容内容" multipleLine>
  2957. 垂直居中对齐<Brief>辅助文字内容</Brief>
  2958. </Item>
  2959. <Item
  2960. wrap
  2961. extra="文字超长折行文字超长折行文字超长折行文字超长折行文字超长折行文字超长折行文字超长折行"
  2962. multipleLine
  2963. align="top"
  2964. arrow="horizontal">
  2965. 顶部对齐
  2966. <Brief>辅助文字内容辅助文字内容辅助文字内容辅助文字内容</Brief>
  2967. <Brief>辅助文字内容</Brief>
  2968. </Item>
  2969. <Item
  2970. extra={
  2971. <View>
  2972. 内容内容
  2973. <Brief style={{ textAlign: 'right' }}>辅助文字内容</Brief>
  2974. </View>
  2975. }
  2976. multipleLine
  2977. align="bottom">
  2978. 底部对齐
  2979. </Item>
  2980. </List>
  2981. <List renderHeader={'带缩略图'}>
  2982. <Item thumb="https://os.alipayobjects.com/rmsportal/mOoPurdIfmcuqtr.png">
  2983. thumb
  2984. </Item>
  2985. <Item
  2986. thumb="https://os.alipayobjects.com/rmsportal/mOoPurdIfmcuqtr.png"
  2987. arrow="horizontal">
  2988. thumb
  2989. </Item>
  2990. <Item
  2991. extra={
  2992. <Image
  2993. source={{
  2994. uri: 'https://os.alipayobjects.com/rmsportal/mOoPurdIfmcuqtr.png',
  2995. }}
  2996. style={{ width: 29, height: 29 }}
  2997. />
  2998. }
  2999. arrow="horizontal">
  3000. extra为Image
  3001. </Item>
  3002. </List>
  3003. </ScrollView>
  3004. )
  3005. }
  3006. }
  3007. export const title = 'List'
  3008. export const description = 'List Example'
  3009. ```
  3010. ## API
  3011. ### List
  3012. Properties | Descrition | Type | Default | Version |
  3013. -----------|------------|------|---------|---------|
  3014. | renderHeader | list heder | (): void | | |
  3015. | renderFooter | list footer | (): void | | |
  3016. | styles | Semantic DOM style | [ListStyle](#liststyle-interface) | - | `5.2.1` |
  3017. ### List.Item
  3018. Properties | Descrition | Type | Default | Version |
  3019. -----------|------------|------|---------|---------|
  3020. | thumb | thumbnail on the left side of `List`(string type will be used to set img src) | String \| React.Element | | |
  3021. | extra | extra content on the right side of `List` | String \| React.Element | | |
  3022. | arrow | arrow direction, options: `horizontal`,`up`,`down`, `empty`; `empty` option may hide the dom | String | | |
  3023. | align | vertical alignment of child elements,options: `top`,`middle`,`bottom` | String | `middle` | | |
  3024. | onPress | callback is called when list is clicked | Same as [TouchableHighlightProps['onPress']](#touchablehighlightprops) | | |
  3025. | multipleLine | multiple line | Boolean | `false` | |
  3026. | wrap | Whether to wrap long texts, otherwise it will be hidden by default. | Boolean | `false` | |
  3027. | styles | Semantic DOM style | [ListItemStyle](#listitemstyle-interface) | - | `5.2.1` |
  3028. ### TouchableHighlightProps
  3029. New in `5.2.1`. In addition, all properties of [TouchableHighlightProps](https://reactnative.dev/docs/touchablehighlight) are supported;
  3030. when setting `onPress` props, it has a default touch style:
  3031. <br/> `{ underlayColor:'#dddddd', activeOpacity: 0.5 }`
  3032. ### List.Item.Brief
  3033. Brief infomation
  3034. Properties | Descrition | Type | Default | Version |
  3035. -----------|------------|------|---------|---------|
  3036. | wrap | Whether to wrap long texts, otherwise it will be hidden by default. | Boolean | `false` | |
  3037. | styles | Semantic DOM style | [BriefStyle](#briefstyle-interface) | - | `5.2.1` |
  3038. ### ListStyle interface
  3039. ```typescript
  3040. interface ListStyle {
  3041. List: ViewStyle
  3042. Header: TextStyle
  3043. Footer: TextStyle
  3044. Body: ViewStyle
  3045. BodyBottomLine: ViewStyle
  3046. }
  3047. ```
  3048. ### ListItemStyle interface
  3049. ```typescript
  3050. interface ListItemStyle {
  3051. underlayColor: ViewStyle // ListItem is a TouchableHighlight
  3052. Item: ViewStyle // ListItem wrap
  3053. Line: ViewStyle // borderBottom
  3054. Thumb: ImageStyle
  3055. Content: TextStyle
  3056. Extra: TextStyle
  3057. Arrow: TextStyle // horizontal arrow
  3058. ArrowV: TextStyle // up/down arrow
  3059. multipleLine: ViewStyle
  3060. multipleThumb: ImageStyle
  3061. }
  3062. ```
  3063. ### BriefStyle interface
  3064. ```typescript
  3065. interface BriefStyle {
  3066. Brief: ViewStyle
  3067. BriefText: TextStyle
  3068. }
  3069. ```
  3070. ---
  3071. ## ListView
  3072. Source: https://rn.mobile.ant.design/components/list-view.md
  3073. # ListView
  3074. Documentation please checkout https://github.com/gameboyVito/react-native-ultimate-listview
  3075. ## Examples
  3076. ```tsx
  3077. import { ListView } from '@ant-design/react-native'
  3078. import React from 'react'
  3079. import { Text, View } from 'react-native'
  3080. export default class BasicListExample extends React.Component<any, any> {
  3081. state = {
  3082. layout: 'list',
  3083. }
  3084. sleep = (time: any) =>
  3085. new Promise((resolve) => setTimeout(() => resolve(''), time))
  3086. onFetch = async (
  3087. page = 1,
  3088. startFetch: (arg0: string[], arg1: number) => void,
  3089. abortFetch: () => void,
  3090. ) => {
  3091. try {
  3092. //This is required to determinate whether the first loading list is all loaded.
  3093. let pageLimit = 30
  3094. if (this.state.layout === 'grid') {
  3095. pageLimit = 60
  3096. }
  3097. const skip = (page - 1) * pageLimit
  3098. //Generate dummy data
  3099. let rowData = Array.from(
  3100. { length: pageLimit },
  3101. (_, index) => `item -> ${index + skip}`,
  3102. )
  3103. //Simulate the end of the list if there is no more data returned from the server
  3104. if (page === 3) {
  3105. rowData = []
  3106. }
  3107. //Simulate the network loading in ES7 syntax (async/await)
  3108. await this.sleep(2000)
  3109. startFetch(rowData, pageLimit)
  3110. } catch (err) {
  3111. abortFetch() //manually stop the refresh or pagination if it encounters network error
  3112. }
  3113. }
  3114. renderItem = (item: any) => {
  3115. return (
  3116. <View style={{ padding: 10 }}>
  3117. <Text>{item}</Text>
  3118. </View>
  3119. )
  3120. }
  3121. render() {
  3122. return (
  3123. <ListView
  3124. onFetch={this.onFetch}
  3125. keyExtractor={(item: any, index: any) =>
  3126. `${this.state.layout} - ${item} - ${index}`
  3127. }
  3128. renderItem={this.renderItem}
  3129. numColumns={this.state.layout === 'list' ? 1 : 3}
  3130. />
  3131. )
  3132. }
  3133. }
  3134. export const title = 'ListView'
  3135. export const description = 'ListView Example'
  3136. ```
  3137. ---
  3138. ## Modal
  3139. Source: https://rn.mobile.ant.design/components/modal.md
  3140. # Modal
  3141. Use to show important information for the system, and ask for user feedback. eg: When deleting an important content, pop up a Modal for secondary confirmation.
  3142. ### Rules
  3143. - Use as few as possible. Modal will interrupt user operation, only use it at important situation.
  3144. - Title should be concise, do not exceed 1 line; description should be concise and complete, generally no more than 2 lines.
  3145. - Operation buttons are up to 3(vertical), generally 1-2(horizontal); [ActionSheet](/components/action-sheet) is preferred when there are more than 3 actions.
  3146. - Generally put the most likely clicked button on the right side. In addition, the cancel button should always be on the left.
  3147. ## Examples
  3148. ```tsx
  3149. import {
  3150. Button,
  3151. List,
  3152. Modal,
  3153. Provider,
  3154. Switch,
  3155. Toast,
  3156. WhiteSpace,
  3157. WingBlank,
  3158. } from '@ant-design/react-native'
  3159. import React from 'react'
  3160. import { ScrollView, Text, View } from 'react-native'
  3161. export default class BasicModalExample extends React.Component<any, any> {
  3162. constructor(props: any) {
  3163. super(props)
  3164. this.state = {
  3165. visible: false,
  3166. visible1: false,
  3167. visible2: false,
  3168. modalType: 'portal',
  3169. }
  3170. }
  3171. onClose = () => {
  3172. this.setState({
  3173. visible: false,
  3174. })
  3175. }
  3176. onClose1 = () => {
  3177. this.setState({
  3178. visible1: false,
  3179. })
  3180. }
  3181. onClose2 = () => {
  3182. this.setState({
  3183. visible2: false,
  3184. })
  3185. }
  3186. onButtonClick = () => {
  3187. Modal.alert('Title', 'alert content', [
  3188. { text: 'Cancel', onPress: () => console.log('cancel'), style: 'cancel' },
  3189. { text: 'OK', onPress: () => console.log('ok') },
  3190. ])
  3191. }
  3192. onButtonClickPromise = () => {
  3193. Modal.alert('Title', 'promise button', [
  3194. {
  3195. text: 'Cancel',
  3196. onPress: () => {
  3197. Toast.info('onPress promise resolve', 1)
  3198. return new Promise((resolve) => {
  3199. setTimeout(resolve, 1000)
  3200. })
  3201. },
  3202. style: 'cancel',
  3203. },
  3204. {
  3205. text: 'Hold on',
  3206. onPress: () => {
  3207. Toast.info('onPress promise reject', 1)
  3208. return new Promise((_, reject) => {
  3209. setTimeout(reject, 1000)
  3210. })
  3211. },
  3212. },
  3213. ])
  3214. }
  3215. onButtonClick2 = () => {
  3216. Modal.operation([
  3217. { text: '标为未读', onPress: () => console.log('标为未读被点击了') },
  3218. { text: '置顶聊天', onPress: () => console.log('置顶聊天被点击了') },
  3219. ])
  3220. }
  3221. onButtonClick3 = () => {
  3222. Modal.prompt(
  3223. 'Login',
  3224. 'Pleas input login information',
  3225. (login: any, password: any) =>
  3226. console.log(`login: ${login}, password: ${password}`),
  3227. 'login-password',
  3228. '',
  3229. ['Please input name', 'Please input password'],
  3230. )
  3231. }
  3232. onButtonClick4 = () => {
  3233. Modal.prompt(
  3234. 'Input password',
  3235. 'password message',
  3236. (password: any) => console.log(`password: ${password}`),
  3237. 'secure-text',
  3238. 'defaultValue',
  3239. )
  3240. }
  3241. onButtonClick5 = () => {
  3242. Modal.prompt(
  3243. 'Name',
  3244. 'name message',
  3245. (password: any) => console.log(`password: ${password}`),
  3246. 'default',
  3247. '',
  3248. ['please input name'],
  3249. )
  3250. }
  3251. onButtonClick6 = () => {
  3252. Modal.operation(
  3253. [
  3254. { text: '标为未读', onPress: () => console.log('标为未读被点击了') },
  3255. { text: '置顶聊天', onPress: () => console.log('置顶聊天被点击了') },
  3256. ],
  3257. () => {
  3258. console.log('返回键点击')
  3259. return false
  3260. },
  3261. )
  3262. }
  3263. render() {
  3264. const footerButtons = [
  3265. { text: 'Cancel', onPress: () => console.log('cancel') },
  3266. { text: 'Ok', onPress: () => console.log('ok') },
  3267. ]
  3268. return (
  3269. <Provider>
  3270. <ScrollView style={{ marginTop: 20 }}>
  3271. <List>
  3272. <List.Item
  3273. extra={
  3274. <Switch
  3275. style={{ width: 70 }}
  3276. checked={this.state.modalType === 'modal'}
  3277. onChange={(val) => {
  3278. this.setState({ modalType: val ? 'modal' : 'portal' })
  3279. }}
  3280. checkedChildren="modal"
  3281. unCheckedChildren="portal"
  3282. />
  3283. }>
  3284. 切换modalType
  3285. <List.Item.Brief>
  3286. `modalType='modal'`时将调用原生Modal{' '}
  3287. </List.Item.Brief>
  3288. </List.Item>
  3289. </List>
  3290. <WingBlank>
  3291. <Button onPress={() => this.setState({ visible: true })}>
  3292. showModal
  3293. </Button>
  3294. <WhiteSpace />
  3295. <Button onPress={() => this.setState({ visible1: true })}>
  3296. transparent:false
  3297. </Button>
  3298. <WhiteSpace />
  3299. <Button onPress={() => this.setState({ visible2: true })}>
  3300. popup
  3301. </Button>
  3302. <WhiteSpace />
  3303. <Button onPress={this.onButtonClick}>Modal.alert</Button>
  3304. <WhiteSpace />
  3305. <Button onPress={this.onButtonClickPromise}>
  3306. Modal.alert (promise)
  3307. </Button>
  3308. <WhiteSpace />
  3309. <Button onPress={this.onButtonClick2}>Modal.opertation</Button>
  3310. <WhiteSpace />
  3311. <Button onPress={this.onButtonClick6}>
  3312. Modal.opertation (onBackHandler)
  3313. </Button>
  3314. <WhiteSpace />
  3315. <Button onPress={this.onButtonClick5}>
  3316. Modal.prompt (default)
  3317. </Button>
  3318. <WhiteSpace />
  3319. <Button onPress={this.onButtonClick3}>
  3320. Modal.prompt (login-password)
  3321. </Button>
  3322. <WhiteSpace />
  3323. <Button onPress={this.onButtonClick4}>
  3324. Modal.prompt (secure-text)
  3325. </Button>
  3326. </WingBlank>
  3327. <Modal
  3328. title="Title"
  3329. transparent
  3330. modalType={this.state.modalType}
  3331. onClose={this.onClose}
  3332. maskClosable
  3333. visible={this.state.visible}
  3334. closable
  3335. footer={footerButtons}>
  3336. <View style={{ paddingVertical: 20 }}>
  3337. <Text style={{ textAlign: 'center' }}>Content...</Text>
  3338. <Text style={{ textAlign: 'center' }}>Content...</Text>
  3339. </View>
  3340. <Button type="primary" onPress={this.onClose}>
  3341. close modal
  3342. </Button>
  3343. </Modal>
  3344. <Modal
  3345. transparent={false}
  3346. modalType={this.state.modalType}
  3347. visible={this.state.visible1}
  3348. animationType="slide-up"
  3349. onClose={this.onClose1}>
  3350. <View style={{ paddingVertical: 220 }}>
  3351. <Text style={{ textAlign: 'center' }}>Content...</Text>
  3352. <Text style={{ textAlign: 'center' }}>Content...</Text>
  3353. </View>
  3354. <Button
  3355. type="primary"
  3356. style={{ marginBottom: 10 }}
  3357. onPress={() => Toast.info('Hello Toast in Modal now works')}>
  3358. {this.state.modalType === 'portal'
  3359. ? 'Hello Toast in Modal now works'
  3360. : "Hello Toast not works when modalType='portal'"}
  3361. </Button>
  3362. <Button type="primary" onPress={this.onClose1}>
  3363. close modal
  3364. </Button>
  3365. </Modal>
  3366. <Modal
  3367. popup
  3368. modalType={this.state.modalType}
  3369. visible={this.state.visible2}
  3370. animationType="slide-up"
  3371. onClose={this.onClose2}>
  3372. <View style={{ paddingVertical: 20, paddingHorizontal: 20 }}>
  3373. <Text style={{ textAlign: 'center' }}>Content...</Text>
  3374. <Text style={{ textAlign: 'center' }}>Content...</Text>
  3375. </View>
  3376. <Button type="primary" onPress={this.onClose2}>
  3377. close modal
  3378. </Button>
  3379. </Modal>
  3380. </ScrollView>
  3381. </Provider>
  3382. )
  3383. }
  3384. }
  3385. ```
  3386. ## API
  3387. ### Modal
  3388. Properties | Descrition | Type | Default | Version
  3389. -----------|------------|------|---------|---------|
  3390. | visible | Determine whether a modal dialog is visible or not | Boolean | false | |
  3391. | closable | Determine whether a close (x) button is visible or not | Boolean | false | |
  3392. | maskClosable | Determine whether to close the modal dialog when clicked mask of it | Boolean | true | |
  3393. | onClose | Callback for clicking close icon x or mask | (): void | - | |
  3394. | transparent | transparent mode or full screen mode | Boolean | false | |
  3395. | popup | popup mode | Boolean | false | |
  3396. | animationDuration | Animation duration, in ms | Number | 300 | `5.3.0` |
  3397. | animationType | Options: 'fade' / 'slide' | String | |fade |
  3398. | modalType | The type of the popup. <br/>When it is `'portal'`, it is inserted from the `<Provider />` root node (default). <br/>When it is `'modal'`, it is the same as [`react-native/Modal`](https://reactnative.dev/docs/modal) (used to get the current context). <br/>When it is `'view'`, it is the same as `react-native/View` (used to nest popups in popups). | `'portal'`\| `'modal'` \| `'view'` | `'portal'` | `5.3.0` |
  3399. | title | title | React.Element | - | |
  3400. | footer | footer content | Array [{text, onPress}] | [] | |
  3401. | onRequestClose | The `onRequestClose` callback is called when the user taps the hardware back button on Android or the menu button on Apple TV. Returns `true` to prevent `BackHandler` events when modal is open.| (): boolean | false | |
  3402. | style | style same as `styles.innerContainer` | `ViewStyle` | - | |
  3403. | styles | Semantic DOM style | [ModalStyle](#modalstyle-interface) | - | |
  3404. ### ModalStyle interface
  3405. ```typescript
  3406. interface ModalStyle {
  3407. container: ViewStyle // Set `z-index`
  3408. wrap: ViewStyle // Set modal flex layout: `{justifyContent: 'center',alignItems: 'center'}`
  3409. innerContainer: ViewStyle // modal content view, default: `{ widh:286 }`
  3410. // modal content fields
  3411. footer: ViewStyle
  3412. header: TextStyle
  3413. body: ViewStyle
  3414. closeWrap: ViewStyle
  3415. close: TextStyle
  3416. buttonGroupH: ViewStyle
  3417. buttonGroupV: ViewStyle
  3418. buttonWrapH: ViewStyle
  3419. buttonWrapV: ViewStyle
  3420. buttonText: TextStyle
  3421. // popup
  3422. popupContainer: ViewStyle
  3423. popupSlideUp: ViewStyle
  3424. popupSlideDown: ViewStyle
  3425. // operation
  3426. operationContainer: ViewStyle
  3427. operationBody: ViewStyle
  3428. buttonTextOperation: TextStyle
  3429. }
  3430. ```
  3431. ### Modal.useModal()
  3432. When you need using Context, you can use `contextHolder` which created by `Modal.useModal` to insert into children. Modal created by hooks will get all the context where `contextHolder` are. Created `modal` has the same creating function with [`Modal.method`](#static-method)(Static method).
  3433. ```jsx
  3434. const [modal, contextHolder] = Modal.useModal();
  3435. React.useEffect(() => {
  3436. modal.alert(
  3437. // ...
  3438. );
  3439. }, []);
  3440. return <View>{contextHolder}</View>;
  3441. ```
  3442. ## Static method
  3443. ### Modal.alert(title, message, actions?)
  3444. Properties | Descrition | Type | Default
  3445. -----------|------------|------|--------
  3446. | title | title | String or React.Element | - |
  3447. | message | message | String or React.Element | - |
  3448. | actions | button group, [{text, onPress, style}] | Array | - |
  3449. | onBackHandler | Callback of the back key (not required), returns true to close modal, false to prevent modal from closing| (): boolean | 无 |
  3450. ### Modal.prompt(title, message, callbackOrActions, type?, defaultValue?)
  3451. Properties | Descrition | Type | Default
  3452. -----------|------------|------|--------
  3453. | title | title | String or React.Element | - |
  3454. | message | message | String or React.Element | - |
  3455. | callbackOrActions | button group [{text, onPress}] or callback | Array or Function | - |
  3456. | type | prompt style | String (`default`, `secure-text`, `login-password`)| `default` |
  3457. | defaultValue | Default(input whick type is password is not supported) | String | - |
  3458. | placeholders | ['', ''] | String[] | - |
  3459. | onBackHandler | Callback of the back key (not required), returns true to close modal, false to prevent modal from closing| (): boolean | 无 |
  3460. ### Modal.operation(actions?, onBackHandler?)
  3461. Properties | Descrition | Type | Default
  3462. -----------|------------|------|--------
  3463. | actions | button group, [{text, onPress, style}] | Array | - |
  3464. | onBackHandler | Callback of the back key (not required), returns true to close modal, false to prevent modal from closing| (): boolean | 无 |
  3465. ## FAQ
  3466. ### How to close the static Modal.method()?
  3467. You need to use `Portal.remove(key)` method; Take `Modal.alert` as an example
  3468. ```jsx
  3469. import { Modal, Portal } from '@ant-design/react-native'
  3470. import { useRef } from 'react'
  3471. function App() {
  3472. const key = useRef()
  3473. const onOpen = () => {
  3474. key.current = Modal.alert({})
  3475. }
  3476. const onClose = () => {
  3477. // close the Modal.alert
  3478. Portal.remove(key)
  3479. }
  3480. }
  3481. ```
  3482. When using `Modal.useModal`, use the `modal.remove(key)` method:
  3483. ```jsx
  3484. import { Modal, Portal } from '@ant-design/react-native'
  3485. import { useRef } from 'react'
  3486. function App() {
  3487. const [modal, contextHolder] = Modal.useModal();
  3488. const key = useRef()
  3489. const onOpen = () => {
  3490. key.current = modal.alert({})
  3491. }
  3492. const onClose = () => {
  3493. // close the modal.alert
  3494. modal.remove(key)
  3495. }
  3496. return (
  3497. <>
  3498. ...
  3499. {contextHolder}
  3500. </>
  3501. )
  3502. }
  3503. ```
  3504. ### Why I can not access context,redux,useRouter in `<Modal />` or `Modal.xxx`?
  3505. Rendering `<Modal>` or calling Modal methods directly is dynamically inserted into the `<Provider>` root node through `Portal.add` by default. At this time, its context is different from the context of the current code, so the context information cannot be obtained.
  3506. When you need context info, <br/>
  3507. **1.** you can use `Modal.useModal` to get `modal` instance and `contextHolder` node. And put it in your children:
  3508. ```tsx
  3509. const [modal, contextHolder] = Modal.useModal();
  3510. // then call modal.confirm instead of Modal.confirm
  3511. return (
  3512. <Context1.Provider value="Ant">
  3513. {/* contextHolder is in Context1, which means modal will get context of Context1 */}
  3514. {contextHolder}
  3515. <Context2.Provider value="Design">
  3516. {/* contextHolder is out of Context2, which means modal will not get context of Context2 */}
  3517. </Context2.Provider>
  3518. </Context1.Provider>
  3519. );
  3520. ```
  3521. **Note**: You must insert `contextHolder` into your children with hooks. You can use origin method if you do not need context connection.
  3522. **2.** When using `<Modal />`, by setting `modalType='modal'`, the **native Modal component** will be used internally to maintain the context:
  3523. ```tsx
  3524. <Modal modelType="modal" ...>
  3525. ...
  3526. </Modal>
  3527. ```
  3528. ---
  3529. ## NoticeBar
  3530. Source: https://rn.mobile.ant.design/components/notice-bar.md
  3531. # NoticeBar
  3532. Component to display a system message, event notice and etc. Which is under the navigation bar.
  3533. ### Rules
  3534. - Be used to attract user's attension, the importance level is lower than `Modal` and higher than `Toast`.
  3535. - It can also achieve a lightweight marquee effect.
  3536. ## Examples
  3537. ```tsx
  3538. import {
  3539. Icon,
  3540. List,
  3541. NoticeBar,
  3542. Picker,
  3543. Provider,
  3544. Slider,
  3545. Switch,
  3546. WhiteSpace,
  3547. } from '@ant-design/react-native'
  3548. import React, { useState } from 'react'
  3549. import { ScrollView, Text } from 'react-native'
  3550. export default function NoticeBarExample() {
  3551. return (
  3552. <Provider>
  3553. <ScrollView style={{ marginBottom: 40 }}>
  3554. {true && (
  3555. <>
  3556. <List renderHeader={'自定义颜色'}>
  3557. <WhiteSpace />
  3558. <NoticeBar>默认</NoticeBar>
  3559. <WhiteSpace />
  3560. <NoticeBar
  3561. styles={{
  3562. font: { color: '#ffffff' },
  3563. background: { backgroundColor: '#f4333c' },
  3564. }}>
  3565. 错误
  3566. </NoticeBar>
  3567. <WhiteSpace />
  3568. <NoticeBar
  3569. styles={{
  3570. font: { color: '#108ee9' },
  3571. background: { backgroundColor: '#d0e4ff' },
  3572. }}>
  3573. 信息
  3574. </NoticeBar>
  3575. <WhiteSpace />
  3576. </List>
  3577. <List renderHeader={'可关闭'}>
  3578. <NoticeBar mode="closable">这条通知可以关闭</NoticeBar>
  3579. </List>
  3580. <List renderHeader={'超长滚动'}>
  3581. <WhiteSpace />
  3582. <NoticeBar marqueeProps={{ loop: true }}>
  3583. Notice: I can be a React component, multiple React components,
  3584. or just some text.
  3585. </NoticeBar>
  3586. <WhiteSpace />
  3587. <NoticeBar
  3588. marqueeProps={{
  3589. loop: true,
  3590. autoFill: true,
  3591. trailing: 0,
  3592. spacing: 10,
  3593. }}>
  3594. autoFill&spacing
  3595. </NoticeBar>
  3596. </List>
  3597. <List renderHeader={'自定义'}>
  3598. <WhiteSpace />
  3599. <NoticeBar
  3600. mode="link"
  3601. onPress={() => {
  3602. console.log('onPress')
  3603. }}>
  3604. mode="link"
  3605. </NoticeBar>
  3606. <WhiteSpace />
  3607. <NoticeBar
  3608. mode="closable"
  3609. icon={<Icon name="compass" style={{ color: '#f4333c' }} />}
  3610. action={
  3611. <Icon name="close-circle" style={{ color: '#f4333c' }} />
  3612. }>
  3613. 自定义图标
  3614. </NoticeBar>
  3615. <WhiteSpace />
  3616. <NoticeBar
  3617. marqueeProps={{ loop: true, autoFill: true }}
  3618. mode="closable"
  3619. action={<Text style={{ color: '#a1a1a1' }}>不再提示</Text>}>
  3620. 自定义右侧功能区 Closable demo for `action`.
  3621. </NoticeBar>
  3622. <WhiteSpace />
  3623. </List>
  3624. </>
  3625. )}
  3626. <List renderHeader={'方向/播放/暂停控制'}>
  3627. <ControlDemo />
  3628. </List>
  3629. </ScrollView>
  3630. </Provider>
  3631. )
  3632. }
  3633. function ControlDemo() {
  3634. const [play, setPlay] = useState(true)
  3635. const [autoFill, setAutoFill] = useState(false)
  3636. const [direction, setDirection] = useState<'left' | 'right' | 'up' | 'down'>(
  3637. 'left',
  3638. )
  3639. const [fps, setFps] = useState(40)
  3640. return (
  3641. <>
  3642. <WhiteSpace />
  3643. <NoticeBar
  3644. marqueeProps={{
  3645. play,
  3646. autoFill,
  3647. direction,
  3648. fps,
  3649. loop: 0,
  3650. }}>
  3651. Notice: I can be a React component, multiple React components, or just
  3652. some text.
  3653. </NoticeBar>
  3654. <WhiteSpace />
  3655. <List.Item extra={<Switch checked={play} onChange={setPlay} />}>
  3656. Play
  3657. </List.Item>
  3658. <List.Item extra={<Switch checked={autoFill} onChange={setAutoFill} />}>
  3659. AutoFill
  3660. </List.Item>
  3661. <Picker
  3662. data={[
  3663. { label: 'Left', value: 'left' },
  3664. { label: 'Right', value: 'right' },
  3665. { label: 'Up', value: 'up' },
  3666. { label: 'Down', value: 'down' },
  3667. ]}
  3668. value={[direction]}
  3669. onChange={(val) => setDirection(val[0] as any)}>
  3670. <List.Item arrow="horizontal">Direction</List.Item>
  3671. </Picker>
  3672. <List.Item>
  3673. <List.Item.Brief>速度fps: {fps}</List.Item.Brief>
  3674. <Slider
  3675. onAfterChange={setFps}
  3676. ticks
  3677. step={10}
  3678. defaultValue={fps}
  3679. popover
  3680. />
  3681. </List.Item>
  3682. </>
  3683. )
  3684. }
  3685. ```
  3686. ## API
  3687. | Properties | Descrition | Type | Default | Version |
  3688. |------------|------------|------|---------|---------|
  3689. | action | text which is used to replace right icon | `ReactNode` | - | |
  3690. | children | The children rendered inside the marquee | `ReactNode` | - | |
  3691. | icon | Set the icon at the start position | `ReactNode` | `<Icon name="sound" color={theme.brand_error} />`| |
  3692. | marqueeProps | marquee params | [MarqueeProps](#marquee-props) | `{loop: false, leading: 500, trailing: 800, fps: 40}` | |
  3693. | mode | Type of NoticeBar. Invalid when `action` is present | `closable`\|`link` | - | |
  3694. | onClose | A callback function, can be executed when you click the `action` icon. Only valid in `mode="closable"` | `() => void` | - | `5.2.1` |
  3695. | onPress | A callback function, can be executed when you click on the operating area | `() => void` | - | |
  3696. | style | Container style | `StyleProp<ViewStyle>` | - | |
  3697. | styles | Semantic DOM style | [NoticeBarStyle](#noticebarstyle-interface) | - | |
  3698. - Theme color [theme.brand_error](https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/style/themes/default.tsx#L35) = `#f4333c`
  3699. ### Marquee props
  3700. | Properties | Descrition | Type | Default | Version |
  3701. |------------|------------|------|---------|---------|
  3702. | autoFill | Whether to automatically fill blank space in the marquee with copies of the children or not | `Boolean` | false | `5.2.1` |
  3703. | direction | The direction the marquee slides | `'left'` \| `'right'` \| `'up'` \| `'down'` | `'left'` | `5.2.2` add `'up'`&`'down'` |
  3704. | fps | Speed calculated as pixels/second | `Number` | 40 | |
  3705. | leading | Duration to delay the animation after first render, in millisecond | `Number` | 500 | |
  3706. | loop | The number of times the marquee should loop, `true/0` is equivalent to infinite | `Boolean` \| `Number` | false | |
  3707. | onFinish | A callback for when the marquee finishes scrolling and stops. Only calls if loop is non-zero or false. | `() => void` | - | `5.2.1` |
  3708. | onCycleComplete | A callback for when the marquee finishes a loop. Does not call if maximum loops are reached (use onFinish instead). | `() => void` | - | `5.2.1` |
  3709. | play | Whether to play or pause the marquee | `Boolean` | true | `5.2.1` |
  3710. | spacing | Spacing between repeting elements, valid when `autoFill={true}` | `Number` | 0 | `5.2.1` |
  3711. | style | The marquee Text style | `TextStyle` | - | |
  3712. | trailing | Duration to delay the animation after previous loop, valid when `autoFill={false}`, in millisecond | `Number` | 800 | |
  3713. | wrapStyle | Marquee wrap view style | `ViewStyle` | - | |
  3714. > Design Reference: [https://github.com/justin-chu/react-fast-marquee](https://github.com/justin-chu/react-fast-marquee), can be used as a marquee component alone
  3715. ```jsx
  3716. // New in 5.2.2
  3717. import { Marquee } from '@ant-design/react-native'
  3718. ```
  3719. ## NoticeBarStyle interface
  3720. `5.2.1`refactored the styles
  3721. ```ts
  3722. interface NoticeBarStyle {
  3723. container: ViewStyle, // Outermost container style, default: {minHeight: 36(theme.notice_bar_height)}
  3724. font: TextStyle, // Font style, default: {color: #f4333c(theme.brand_error)}
  3725. background: ViewStyle, // Background color, default: {backgroundColor: #fffada}
  3726. marquee: TextStyle, // marquee font style
  3727. iconWrap: ViewStyle, // left icon wrap
  3728. actionWrap: ViewStyle, // right action wrap
  3729. close: ViewStyle, // mode="closeable" icon
  3730. link: ViewStyle // mode="link" icon
  3731. }
  3732. ```
  3733. ## Ref
  3734. New in `5.2.1`. Ref to MarqueeActions.
  3735. | Properties | Descrition | Type|
  3736. |-----|------|------|
  3737. | play | Start the marquee text rolling | `() => void` |
  3738. | pause | Pause the marquee text | `() => void` |
  3739. | stop | Return the marquee text to the original position | `() => void` |
  3740. ---
  3741. ## Pagination
  3742. Source: https://rn.mobile.ant.design/components/pagination.md
  3743. # Pagination
  3744. A long list can be divided into several pages by `Pagination`, and only one page will be loaded at a time.
  3745. ### Rule
  3746. - When it will take a long time to load/render all items.
  3747. ## Examples
  3748. ```tsx
  3749. import { Pagination, WhiteSpace, WingBlank } from '@ant-design/react-native'
  3750. import React from 'react'
  3751. const locale = {
  3752. prevText: '上一步',
  3753. nextText: '下一步',
  3754. }
  3755. export default class BasicPaginationExample extends React.Component<any, any> {
  3756. render() {
  3757. return (
  3758. <WingBlank size="lg">
  3759. <WhiteSpace size="lg" />
  3760. <Pagination total={5} current={1} locale={locale} />
  3761. <WhiteSpace size="lg" />
  3762. <Pagination simple total={5} current={1} locale={locale} />
  3763. <WhiteSpace size="lg" />
  3764. <Pagination mode="number" total={5} current={3} />
  3765. <WhiteSpace size="lg" />
  3766. <Pagination mode="pointer" total={5} current={2} />
  3767. </WingBlank>
  3768. )
  3769. }
  3770. }
  3771. ```
  3772. ## API
  3773. Properties | Descrition | Type | Default
  3774. -----------|------------|------|--------
  3775. | mode | the mode of `Pagination` which can be one of `button`,`number`,`pointer` | string | `button` |
  3776. | current | current page index | number | 1 |
  3777. | total | total number of data | number | 0 |
  3778. | simple | whether to hide number | boolean | false |
  3779. | disabled | whether is disabled | boolean | false |
  3780. | locale | [i18n](/components/locale-provider/) setting, you can override the configuration of the global `LocaleProvider | Object:{prevText, nextText} | |
  3781. | onChange | invoked with the new index when the value changes. | (index: Number): void | |
  3782. ---
  3783. ## Picker
  3784. Source: https://rn.mobile.ant.design/components/picker.md
  3785. # Picker
  3786. Choose from a set of data, e.g. Country choice.
  3787. ### Rules
  3788. - Try to use Picker to help users complete the input, to avoid the user through the keyboard directly input.
  3789. - DatePicker is Picker's specific pattern.
  3790. ## Examples
  3791. ```tsx
  3792. import {
  3793. Button,
  3794. List,
  3795. Picker,
  3796. PickerValue,
  3797. PickerValueExtend,
  3798. Provider,
  3799. } from '@ant-design/react-native'
  3800. import { district } from 'antd-mobile-demo-data'
  3801. import React, { useState } from 'react'
  3802. import { Text, TouchableOpacity, View } from 'react-native'
  3803. const CustomChildren = (props: any) => (
  3804. <TouchableOpacity onPress={props.onPress}>
  3805. <View
  3806. style={{
  3807. height: 36,
  3808. paddingLeft: 15,
  3809. flexDirection: 'row',
  3810. alignItems: 'center',
  3811. }}>
  3812. <Text style={{ flex: 1 }}>{props.children}</Text>
  3813. <Text style={{ textAlign: 'right', color: '#888', marginRight: 15 }}>
  3814. {props.extra}
  3815. </Text>
  3816. </View>
  3817. </TouchableOpacity>
  3818. )
  3819. // visible用法
  3820. function BasicDemo() {
  3821. const [visible, setVisible] = useState(false)
  3822. const [value, setValue] = useState<any[]>([])
  3823. const [extend, setExtend] = useState<any>()
  3824. return (
  3825. <View
  3826. style={{
  3827. flexDirection: 'row',
  3828. alignItems: 'center',
  3829. paddingVertical: 5,
  3830. paddingLeft: 16,
  3831. }}>
  3832. <Button
  3833. type="primary"
  3834. onPress={() => {
  3835. setVisible(true)
  3836. }}>
  3837. 选择
  3838. </Button>
  3839. {/* extend渲染所选值 */}
  3840. <Text>
  3841. {extend?.items?.map((item: any) => item.label).join(',') || ' 未选择'}
  3842. </Text>
  3843. {/* visible控制显示/隐藏 */}
  3844. <Picker
  3845. data={district}
  3846. cols={3}
  3847. onChange={setValue}
  3848. onVisibleChange={(v) => {
  3849. setVisible(v)
  3850. }}
  3851. visible={visible}
  3852. value={value}
  3853. onOk={(v: PickerValue[], ext: PickerValueExtend) => {
  3854. setValue(v)
  3855. setExtend(ext)
  3856. }}
  3857. />
  3858. </View>
  3859. )
  3860. }
  3861. export default class PopupExample extends React.Component<any, any> {
  3862. constructor(props: any) {
  3863. super(props)
  3864. this.state = {
  3865. data: [],
  3866. value: [],
  3867. pickerValue: [],
  3868. }
  3869. }
  3870. onPress = () => {
  3871. setTimeout(() => {
  3872. this.setState({
  3873. data: district,
  3874. })
  3875. }, 500)
  3876. }
  3877. onChange = (value: any) => {
  3878. this.setState({ value })
  3879. }
  3880. render() {
  3881. return (
  3882. <Provider>
  3883. <List renderHeader={'List Children'}>
  3884. <Picker
  3885. data={district}
  3886. cols={3}
  3887. value={this.state.value}
  3888. onChange={this.onChange}>
  3889. <List.Item arrow="horizontal">省市选择</List.Item>
  3890. </Picker>
  3891. <Picker
  3892. data={this.state.data}
  3893. cols={2}
  3894. value={this.state.value}
  3895. onChange={this.onChange}>
  3896. <List.Item arrow="horizontal" onPress={this.onPress}>
  3897. 省市选择(异步加载)
  3898. </List.Item>
  3899. </Picker>
  3900. <Picker
  3901. title="选择地区"
  3902. data={district}
  3903. cols={2}
  3904. value={this.state.pickerValue}
  3905. onChange={(v: any) => this.setState({ pickerValue: v })}
  3906. onOk={(v: any) => this.setState({ pickerValue: v })}>
  3907. <CustomChildren>Customized children</CustomChildren>
  3908. </Picker>
  3909. </List>
  3910. <List renderHeader={'visible 控制显示/隐藏'}>
  3911. <BasicDemo />
  3912. </List>
  3913. </Provider>
  3914. )
  3915. }
  3916. }
  3917. ```
  3918. ## API
  3919. ### Props
  3920. ```ts
  3921. type PickerColumnItem = {
  3922. label: string | ReactNode
  3923. value: string | number
  3924. key?: string | number
  3925. children?: PickerColumnItem[]
  3926. }
  3927. type PickerColumn = PickerColumnItem[]
  3928. type PickerValue = string | number
  3929. type PickerValueExtend = {
  3930. columns: PickerColumn[]
  3931. items: (PickerColumnItem | undefined)[]
  3932. }
  3933. ```
  3934. Properties | Descrition | Type | Default | Version
  3935. -----------|------------|------|--------|--------
  3936. | data | data source | `PickerColumn` / `PickerColumn[]` | - | |
  3937. | value | Selected options | `PickerValue[]` | - | |
  3938. | defaultValue | Default selected options | `PickerValue[]` | - | |
  3939. | cascade | whether cascade <br/>child cascade get from `data[].children` | Boolean | `true` | |
  3940. | cols | col numbers | Number | `3` | |
  3941. | onChange | selected callback function, can use [Form](/components/form) | `(value: PickerValue[], extend: PickerValueExtend) => void` | - | |
  3942. | onPickerChange | trigger on each column of selected data is changed | `(value: PickerValue[], index: number) => void` | - | |
  3943. | onVisibleChange | visible state change callback | `(visible: bool): void` | - | |
  3944. | renderLabel | The function to custom rendering the label shown on a column | `(item: PickerColumnItem, itemIndex: number, colIndex: number) => ReactNode` | `(item) => item.label` | `5.2.2` |
  3945. | locale | international, can override the configuration of the global [Provider](/components/provider)'s `locale` | Object: Object: {okText, dismissText, extra} | - | |
  3946. | title | title | ReactNode | - | |
  3947. | okText | ok text | String | `确定` | |
  3948. | dismissText | dismiss text | String | `取消` | |
  3949. | onOk | handler called when click ok | `(value: PickerValue[], extend: PickerValueExtend) => void` | - | |
  3950. | onDismiss | handler called when click cancel | (): void | - | |
  3951. | okButtonProps | The ok button props | [TouchableHighlightProps](https://reactnative.dev/docs/touchablehighlight) | `{ activeOpacity:1, underlayColor:'#ddd' }` | `5.1.3` |
  3952. | dismissButtonProps | The dismiss button props | [TouchableHighlightProps](https://reactnative.dev/docs/touchablehighlight) | `{ activeOpacity:1, underlayColor:'#ddd' }` | `5.1.3` |
  3953. | visible | Whether to show or hide the Picker | Boolean | - | |
  3954. | loading | Should the Picker displays as loading state | Boolean | - | `5.1.0` |
  3955. | loadingContent | The loading content displayed in loading state | ReactNode | - | `5.1.0` |
  3956. | indicatorStyle | style of default Indicator | Object | - | |
  3957. ### Custom Style
  3958. Properties | Descrition | Type | Default | Version
  3959. -----------|------------|------|---------|---------
  3960. | style | style | `StyleProp<ViewStyle>` | - | |
  3961. | styles | inner component styles | [PickerStyle](#pickerstyle-interface) & [PickerViewStyle](/components/picker-view/#pickerviewstyle-interface) | - | `5.1.0`refactored |
  3962. | itemStyle| style to apply to each of the item labels | `StyleProp<TextStyle>` | - | |
  3963. | itemHeight | Height of option item, calculated by `numberOfLines` when without value; `itemStyle` was not allowed to set `{height}` | Number | - | |
  3964. | numberOfLines | Used to truncate the text with an ellipsis after computing the text layout, including line wrapping, such that the total number of lines does not exceed this number | Number | `1` | |
  3965. ### PickerStyle interface
  3966. ```jsx
  3967. interface PickerStyle extends Partial<PickerViewStyle> {
  3968. // modal style
  3969. modal: ViewStyle
  3970. container: ViewStyle
  3971. header: ViewStyle
  3972. headerItem: ViewStyle
  3973. actionText: TextStyle
  3974. title: TextStyle
  3975. okText: TextStyle
  3976. dismissText: TextStyle
  3977. }
  3978. ```
  3979. #### Mask View
  3980. New in `5.1.0`. Support custom mask style, such as using the gradient component `<LinearGradient />`. Default is white translucency.
  3981. Properties | Descrition | Type | Default
  3982. -----------|------------|------|--------
  3983. | renderMaskTop | The function to custom rendering the mask top half view | `()=> ReactNode` | `<View style={{ flex: 1, opacity:0.8, backgroundColor: theme.fill_base }} />` |
  3984. | renderMaskBottom | The function to custom rendering the mask bottom half view | `()=> ReactNode` | `<View style={{ flex: 1, opacity:0.8, backgroundColor: theme.fill_base }} />` |
  3985. - Theme color [theme.fill_base](https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/style/themes/default.tsx#L24) = `#ffffff`
  3986. ### Custom Children
  3987. Picker's children is best to [List.Item](/components/list/#List.Item), if not, need to be a custom component (the `onPress`/`extra` props need to be handled in the component):
  3988. Properties | Descrition | Type | Default | Version |
  3989. -----------|------------|------|--------|--------
  3990. | children| usually `List.Item` | `ReactNode`/`({disabled, extra, value, toggle})=>ReactNode` | - | `5.2.1` add function as Children |
  3991. | extra | Picker's children `extra` prop, display when no `value`(Similar to a placeholder) | String | `please select` | |
  3992. | format | a function that formats the selected value | (labels: string[]): any | `(labels) => { return labels.join(','); } ` | |
  3993. | triggerType | Press event name | String | `onPress` | |
  3994. | disabled | set disabled | Boolean | `false` | |
  3995. ### PickerActions
  3996. Properties | Descrition | Type
  3997. -----------|------------|-----
  3998. | close | Close Picker | `() => void` |
  3999. | open | Open Picker | `() => void` |
  4000. | toggle | Toggle the visible state of Picker | `() => void` |
  4001. ### Ref
  4002. Same as PickerActions
  4003. ## FAQ
  4004. ### Why is the Picker hidden when it popup in the native Modal?
  4005. By default, `<Picker />` is dynamically inserted into the `<Provider>` root node via `Portal.add`, and the zIndex level of the native Modal is above everything, including its root node.
  4006. So if you must use the `<Picker />` component in the native Modal, you can set `modalType='modal'` to keep it at the same level as the native Modal.
  4007. ```tsx
  4008. import {Modal} from 'react-native';
  4009. import {Picker} from '@ant-design/react-native';
  4010. <Modal>
  4011. ...
  4012. <Picker
  4013. modalType="modal" // add here
  4014. visible={visible}
  4015. data={data}>
  4016. <List.Item arrow="horizontal">省市选择</List.Item>
  4017. </Picker>
  4018. </Modal>
  4019. ```
  4020. ---
  4021. ## PickerView
  4022. Source: https://rn.mobile.ant.design/components/picker-view.md
  4023. # PickerView
  4024. PickerView's functions like Picker, but it is rendered directly in the area instead of the pop-up window.
  4025. ## Examples
  4026. ```tsx
  4027. import { List, PickerView } from '@ant-design/react-native'
  4028. import React from 'react'
  4029. import { ScrollView } from 'react-native'
  4030. const basicColumns = [
  4031. [
  4032. { label: '周一', value: 'Mon' },
  4033. { label: '周二', value: 'Tues' },
  4034. { label: '周三', value: 'Wed' },
  4035. { label: '周四', value: 'Thur' },
  4036. { label: '周五', value: 'Fri' },
  4037. ],
  4038. [
  4039. { label: '上午', value: 'am' },
  4040. { label: '下午', value: 'pm' },
  4041. ],
  4042. ]
  4043. export default class PickerViewExample extends React.Component {
  4044. state = {
  4045. value: undefined,
  4046. }
  4047. onChange = (value: any) => {
  4048. this.setState({
  4049. value,
  4050. })
  4051. }
  4052. render() {
  4053. return (
  4054. <ScrollView
  4055. nestedScrollEnabled // 🚩 Enables nested scrolling for Android API level 21+. Nested scrolling is supported by default on iOS.
  4056. >
  4057. <List renderHeader={'基础用法'}>
  4058. <PickerView data={basicColumns} cascade={false} />
  4059. </List>
  4060. <List renderHeader={'自定义高度'}>
  4061. <PickerView
  4062. data={basicColumns}
  4063. cascade={false}
  4064. style={{ height: 450 }}
  4065. itemHeight={55}
  4066. itemStyle={{
  4067. padding: 0,
  4068. }}
  4069. />
  4070. </List>
  4071. <List renderHeader={'受控模式'}>
  4072. <PickerView
  4073. onChange={this.onChange}
  4074. value={this.state.value}
  4075. data={basicColumns}
  4076. cascade={false}
  4077. />
  4078. </List>
  4079. </ScrollView>
  4080. )
  4081. }
  4082. }
  4083. ```
  4084. ## API
  4085. ### Props
  4086. Properties | Descrition | Type | Default | Version
  4087. -----------|------------|------|---------|---------
  4088. | data | data source | `PickerColumn` / `PickerColumn[]` | - | |
  4089. | value | Selected options | `PickerValue[]` | - | |
  4090. | defaultValue | Default selected options | `PickerValue[]` | - | |
  4091. | cascade | whether cascade <br/>child cascade get from `data[].children` | Boolean | `true` | |
  4092. | cols | col numbers | Number | `3` | |
  4093. | onChange | selected callback function, can use [Form](/components/form) | `(value: PickerValue[], extend: PickerValueExtend) => void` | - | |
  4094. | renderLabel | The function to custom rendering the label shown on a column | `(item: PickerColumnItem, itemIndex: number, colIndex: number) => ReactNode` | `(item) => item.label` | `5.2.2` |
  4095. | loading | Should the Picker displays as loading state | Boolean | - | `5.1.0` |
  4096. | loadingContent | The loading content displayed in loading state | ReactNode | `<ActivityIndicator/>` | `5.1.0` |
  4097. | indicatorStyle | style of default Indicator | Object | - | |
  4098. For the type definition of `PickerColumnItem` `PickerColumn` `PickerValue` `PickerValueExtend`, please refer to the document of [Picker](/components/picker/).
  4099. ### Custom Style
  4100. Properties | Descrition | Type | Default | Version
  4101. -----------|------------|------|---------|---------
  4102. | style | style | `StyleProp<ViewStyle>` | - | |
  4103. | styles | Semantic DOM style | [PickerViewStyle](#pickerviewstyle-interface) | - | `5.1.0`refactored |
  4104. | itemStyle| style to apply to each of the item labels | `StyleProp<TextStyle>` | - | |
  4105. | itemHeight | Height of option item, calculated by `numberOfLines` when without value; `itemStyle` was not allowed to set `{height}` | Number | - | |
  4106. | numberOfLines | Used to truncate the text with an ellipsis after computing the text layout, including line wrapping, such that the total number of lines does not exceed this number | Number | `1` | |
  4107. #### PickerViewStyle interface
  4108. ```jsx
  4109. interface PickerViewStyle {
  4110. wrappper: ViewStyle
  4111. wheelWrapper: ViewStyle
  4112. // item style
  4113. itemWrap: ViewStyle
  4114. itemStyle: TextStyle
  4115. itemActiveStyle: TextStyle // New in `5.2.2`
  4116. // mask view
  4117. mask: ViewStyle
  4118. maskTop: ViewStyle
  4119. maskMiddle: ViewStyle
  4120. maskBottom: ViewStyle
  4121. }
  4122. ```
  4123. #### Mask View
  4124. New in `5.1.0`. Support custom mask style, such as using the gradient component `<LinearGradient />`. Default is white translucency.
  4125. Properties | Descrition | Type | Default
  4126. -----------|------------|------|--------
  4127. | renderMaskTop | The function to custom rendering the mask top half view | `()=> ReactNode` | `<View style={{ flex: 1, opacity:0.8, backgroundColor: theme.fill_base }} />` |
  4128. | renderMaskBottom | The function to custom rendering the mask bottom half view | `()=> ReactNode` | `<View style={{ flex: 1, opacity:0.8, backgroundColor: theme.fill_base }} />` |
  4129. - Theme color [theme.fill_base](https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/style/themes/default.tsx#L24) = `#ffffff`
  4130. ## FAQ
  4131. ### On the Android platform, when using `PickerView` nested in `ScrollView`, the Picker Item cannot slide. What should I do?
  4132. Support in `5.1.3`. Set the `nestedScrollEnabled` property of `ScrollView` to `true`.
  4133. ```jsx
  4134. <ScrollView nestedScrollEnabled={true}>
  4135. ...
  4136. <PickerView />
  4137. </ScrollView>
  4138. ```
  4139. ---
  4140. ## Popover
  4141. Source: https://rn.mobile.ant.design/components/popover.md
  4142. # Popover
  4143. > This package has been deprecated in `5.2.1`, recommend [components/Tooltip](/components/tooltip)
  4144. After clicking on a control or an area, a Popover menu appears for doing more.
  4145. If set mask prop, it is recommended to exit by clicking on any of the mask layers.
  4146. ## Examples
  4147. ```tsx
  4148. import { List, Popover } from '@ant-design/react-native'
  4149. import React from 'react'
  4150. import { Easing, StyleSheet, Text, View } from 'react-native'
  4151. const Item = Popover.Item
  4152. export default class PopoverExample extends React.Component<any, any> {
  4153. constructor(props: any) {
  4154. super(props)
  4155. this.state = {
  4156. selected: '',
  4157. }
  4158. }
  4159. onSelect = (value: any) => {
  4160. this.setState({
  4161. // visible: false,
  4162. selected: value,
  4163. })
  4164. }
  4165. render() {
  4166. let overlay = [1, 2, 3].map((i, index) => (
  4167. <Item key={index} value={`option ${i}`}>
  4168. <Text>option {i}</Text>
  4169. </Item>
  4170. ))
  4171. overlay = overlay.concat([
  4172. <Item key="4" value="disabled" disabled>
  4173. <Text style={{ color: '#ddd' }}>disabled opt</Text>
  4174. </Item>,
  4175. <Item key="6" value="button ct" style={{ backgroundColor: '#efeff4' }}>
  4176. <Text>关闭</Text>
  4177. </Item>,
  4178. ])
  4179. return (
  4180. <React.Fragment>
  4181. <List>
  4182. {[1, 2, 3, 4, 5, 6, 7, 8].map((item) =>
  4183. this.renderList(overlay, item),
  4184. )}
  4185. </List>
  4186. <Popover
  4187. overlay={
  4188. <Popover.Item value={'test'}>
  4189. <Text>自定义组件 x</Text>
  4190. </Popover.Item>
  4191. }
  4192. renderOverlayComponent={(nodes) => (
  4193. <View>
  4194. <Text
  4195. style={{
  4196. paddingHorizontal: 9,
  4197. paddingTop: 16,
  4198. color: '#2b2b2b',
  4199. fontWeight: 'bold',
  4200. }}>
  4201. 我是自定义组件title
  4202. </Text>
  4203. {nodes}
  4204. </View>
  4205. )}>
  4206. <Text
  4207. style={{
  4208. margin: 16,
  4209. }}>
  4210. 自定义组件
  4211. </Text>
  4212. </Popover>
  4213. <Popover
  4214. overlay={overlay}
  4215. useNativeDriver
  4216. duration={200}
  4217. easing={(show) => (show ? Easing.in(Easing.ease) : Easing.step0)}>
  4218. <Text
  4219. style={{
  4220. margin: 16,
  4221. }}>
  4222. 自定义动画
  4223. </Text>
  4224. </Popover>
  4225. <View style={{ alignItems: 'center' }}>
  4226. <Text
  4227. style={{
  4228. margin: 16,
  4229. color: 'red',
  4230. }}>
  4231. 如果你设置了 placement 属性请确保你的内容够位置显示,默认是 auto
  4232. 自动计算位置
  4233. </Text>
  4234. {['left', 'right', 'top', 'bottom'].map((p) => (
  4235. <Popover
  4236. key={p}
  4237. overlay={
  4238. <Popover.Item value={p}>
  4239. <Text>自定义组件 {p}</Text>
  4240. </Popover.Item>
  4241. }
  4242. placement={p as any}>
  4243. <Text
  4244. style={{
  4245. margin: 16,
  4246. }}>
  4247. {p}
  4248. </Text>
  4249. </Popover>
  4250. ))}
  4251. </View>
  4252. </React.Fragment>
  4253. )
  4254. }
  4255. private renderList(overlay: React.ReactNode[], key: number) {
  4256. return (
  4257. <List.Item
  4258. key={key}
  4259. extra={
  4260. <Popover
  4261. overlay={overlay}
  4262. triggerStyle={styles.triggerStyle}
  4263. onSelect={(v) =>
  4264. this.setState({
  4265. [`selected${key}`]: v,
  4266. })
  4267. }>
  4268. <Text>菜单</Text>
  4269. </Popover>
  4270. }>
  4271. <View>
  4272. <Text>选择了:{this.state[`selected${key}`]}</Text>
  4273. </View>
  4274. </List.Item>
  4275. )
  4276. }
  4277. }
  4278. const styles = StyleSheet.create({
  4279. triggerStyle: {
  4280. paddingHorizontal: 6,
  4281. },
  4282. })
  4283. export const title = 'Popover'
  4284. export const description = 'Popover example'
  4285. ```
  4286. ## API
  4287. ### Popover
  4288. Properties | Descrition | Type | Default
  4289. -----------|------------|------|--------
  4290. | overlay | Popup layer content | ReactNode | - |
  4291. | placement | How to position the popover | 'top | right | bottom | left | auto' | auto |
  4292. | onSelect | when an option is selected | (value: any): void | - |
  4293. | triggerStyle | trigger style | ViewStyle | - |
  4294. | renderOverlayComponent | A function that renders takes in the MenuOptions element and renders a container element that contains the options. Default function wraps options with a `ScrollView`. e.g. `(nodes) => <View>{nodes}</View>` | (node: React.ReactNode) => React.ReactNode | - |
  4295. | duration | Animation duration | number | 300 |
  4296. | easing | Function that returns easing function for show or hide animation, depending on `show` argument | (show: boolean) => (value: number) => number | show => show ? Easing.out(Easing.back(1.70158)) : Easing.inOut(Easing.quad) |
  4297. | useNativeDriver | Defines if animations should use native driver | boolean | false |
  4298. | onDismiss | Callback to be fired after the popup closes | function | - |
  4299. ### Popover.Item
  4300. Properties | Descrition | Type | Default
  4301. -----------|------------|------|--------
  4302. | disabled | set disabled | Boolean | false |
  4303. | style | item style | ViewStyle | - |
  4304. | value | can be used as the selected option ID | any | - |
  4305. ---
  4306. ## Progress
  4307. Source: https://rn.mobile.ant.design/components/progress.md
  4308. # Progress
  4309. Progress Bar to indicate your task's progress.
  4310. ### Rules
  4311. - When you need a accurate progress,otherwise you should use ActivityIndicator.
  4312. - Hide the unfilled part when used with NavBar for better visual feeling.
  4313. ## Examples
  4314. ```tsx
  4315. import { Button, Progress, WhiteSpace } from '@ant-design/react-native'
  4316. import React from 'react'
  4317. import { Text, View, ViewStyle } from 'react-native'
  4318. export default class BasicProgressExample extends React.Component<any, any> {
  4319. constructor(props: any) {
  4320. super(props)
  4321. this.state = {
  4322. percent: 40,
  4323. }
  4324. }
  4325. onAdd = () => {
  4326. let p = this.state.percent + 10
  4327. if (this.state.percent >= 100) {
  4328. p = 0
  4329. }
  4330. this.setState({ percent: p })
  4331. }
  4332. render() {
  4333. const style = {
  4334. marginTop: 80,
  4335. flexDirection: 'row',
  4336. justifyContent: 'space-between',
  4337. alignItems: 'center',
  4338. }
  4339. return (
  4340. <View>
  4341. <Progress percent={90} position="fixed" />
  4342. <View style={[style as ViewStyle]}>
  4343. <View style={{ marginRight: 10, height: 4, flex: 1 }}>
  4344. <Progress percent={this.state.percent} />
  4345. </View>
  4346. <Text>{this.state.percent}%</Text>
  4347. </View>
  4348. <Button
  4349. style={{ width: 50, marginLeft: 10 }}
  4350. type="ghost"
  4351. size="small"
  4352. onPress={this.onAdd}>
  4353. (+-)10
  4354. </Button>
  4355. <WhiteSpace />
  4356. <Progress percent={5} />
  4357. </View>
  4358. )
  4359. }
  4360. }
  4361. ```
  4362. ## API
  4363. Properties | Descrition | Type | Default
  4364. -----------|------------|------|--------
  4365. percent | percent value of progress | number | 0
  4366. position | position of progress bar, optional:`fixed` `normal` | string | `fixed`
  4367. unfilled | whether to fill unfinished part of progress | boolean | true
  4368. style | the style of container | object | {}
  4369. barStyle | the style of bar | object | {}
  4370. ---
  4371. ## Provider
  4372. Source: https://rn.mobile.ant.design/components/provider.md
  4373. # Provider
  4374. `Provider` provides a uniform localization support for built-in text of components.
  4375. ## When to use
  4376. - You want to use other languages than `Chinese`
  4377. - You want to change the default theme color.
  4378. - You want to add vibration feedback to built-in component.
  4379. - You want to use the `Portal component`.
  4380. ## Examples
  4381. ```tsx
  4382. import {
  4383. DatePicker,
  4384. List,
  4385. Pagination,
  4386. Picker,
  4387. Provider,
  4388. SearchBar,
  4389. WhiteSpace,
  4390. WingBlank,
  4391. } from '@ant-design/react-native'
  4392. import enUS from '@ant-design/react-native/lib/locale-provider/en_US'
  4393. import esES from '@ant-design/react-native/lib/locale-provider/es_ES'
  4394. import faIR from '@ant-design/react-native/lib/locale-provider/fa_IR'
  4395. import koKR from '@ant-design/react-native/lib/locale-provider/ko_KR'
  4396. import ptBR from '@ant-design/react-native/lib/locale-provider/pt_BR'
  4397. import ruRU from '@ant-design/react-native/lib/locale-provider/ru_RU'
  4398. import svSE from '@ant-design/react-native/lib/locale-provider/sv_SE'
  4399. import zhCN from '@ant-design/react-native/lib/locale-provider/zh_CN'
  4400. import React from 'react'
  4401. import { View } from 'react-native'
  4402. const maxDate = new Date(2018, 11, 3, 22, 0)
  4403. const minDate = new Date(2015, 7, 6, 8, 30)
  4404. const seasons = [
  4405. [
  4406. {
  4407. label: '2013',
  4408. value: '2013',
  4409. },
  4410. {
  4411. label: '2014',
  4412. value: '2014',
  4413. },
  4414. ],
  4415. [
  4416. {
  4417. label: '春',
  4418. value: '春',
  4419. },
  4420. {
  4421. label: '夏',
  4422. value: '夏',
  4423. },
  4424. ],
  4425. ]
  4426. const Page = React.memo(() => (
  4427. <View>
  4428. <Pagination total={5} current={1} />
  4429. <WhiteSpace />
  4430. <List style={{ backgroundColor: 'white' }}>
  4431. <DatePicker
  4432. mode="date"
  4433. title="Select date"
  4434. minDate={minDate}
  4435. maxDate={maxDate}>
  4436. <List.Item arrow="horizontal">DatePicker</List.Item>
  4437. </DatePicker>
  4438. <Picker data={seasons} cascade={false}>
  4439. <List.Item arrow="horizontal">Picker</List.Item>
  4440. </Picker>
  4441. <WhiteSpace />
  4442. <SearchBar placeholder="Search" showCancelButton />
  4443. </List>
  4444. </View>
  4445. ))
  4446. export default class LocaleProviderExample extends React.Component<any, any> {
  4447. constructor(props: any) {
  4448. super(props)
  4449. this.state = {
  4450. locale: 'English',
  4451. }
  4452. }
  4453. onChange = (value: any) => {
  4454. this.setState({
  4455. locale: value[0],
  4456. })
  4457. }
  4458. render() {
  4459. const { locale } = this.state
  4460. const languages: Array<any> = [
  4461. {
  4462. value: '中国',
  4463. label: '中国',
  4464. language: zhCN,
  4465. },
  4466. {
  4467. value: 'English',
  4468. label: 'English',
  4469. language: enUS,
  4470. },
  4471. {
  4472. value: 'Русский',
  4473. label: 'Русский',
  4474. language: ruRU,
  4475. },
  4476. {
  4477. value: 'Español',
  4478. label: 'Español',
  4479. language: esES,
  4480. },
  4481. {
  4482. value: 'Português - BR',
  4483. label: 'Português - BR',
  4484. language: ptBR,
  4485. },
  4486. {
  4487. value: 'Sverige',
  4488. label: 'Sverige',
  4489. language: svSE,
  4490. },
  4491. {
  4492. value: 'Persian',
  4493. label: 'Persian',
  4494. language: faIR,
  4495. },
  4496. {
  4497. value: '한국',
  4498. label: '한국',
  4499. language: koKR,
  4500. },
  4501. ]
  4502. const currentLocale = languages.find(
  4503. (item) => item.value === locale,
  4504. ).language
  4505. return (
  4506. <Provider locale={currentLocale}>
  4507. <WingBlank>
  4508. <Picker
  4509. data={languages}
  4510. onChange={this.onChange}
  4511. cols={1}
  4512. value={[locale]}>
  4513. <List.Item arrow="horizontal">Choose language</List.Item>
  4514. </Picker>
  4515. <WhiteSpace />
  4516. <Page />
  4517. </WingBlank>
  4518. </Provider>
  4519. )
  4520. }
  4521. }
  4522. ```
  4523. ### Portal Component
  4524. `ActionSheet` `Modal` `Picker` `Toast` `ToolTip` belongs to Portal component;
  4525. To use these components, you must wrap your root component (usually in App.js) with `Provider` component.
  4526. ## API
  4527. | Property | Description | Type | Default | Version |
  4528. | -----|-----|-----|-------|------|
  4529. | locale | Language package setting(`The default language is Chinese`), <br/>you can find the packages in this path: [`@ant-design/react-native/lib/locale-provider/`](https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/locale-provider) | [Locale](https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/locale-provider/index.tsx#L4) | - | |
  4530. | theme | Theme customization, you can override some or all variables as needed | [Theme](https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/style/themes/default.tsx) | - | |
  4531. | onHaptics | Set the vibration engine. This method will be triggered when the built-in component needs vibration feedback. | `(componentName: 'picker' | 'stepper' | 'slider' | 'switch') => void` | - | `5.2.1` |
  4532. | isRTL | Whether use Right-to-Left (RTL) languages. <br/>Currently only applies to `<SwipeAction/>` | `Boolean` | `I18nManager.isRTL` | `5.2.1` |
  4533. ## FAQ
  4534. ### How do I customize my theme?
  4535. For example: Modifying the following theme variables has a relatively large impact
  4536. ```jsx
  4537. <Provider theme={{
  4538. brand_primary: palette[5], // Brand base color #108ee9
  4539. fill_base: palette[0], // Component default background color #ffffff
  4540. primary_button_fill: palette[5], // <Button type="primary"> background color
  4541. primary_button_fill_tap: palette[3], // <Button type="primary"> onTap background color
  4542. color_icon_base: palette[4], // Background color for many icons
  4543. }}>
  4544. ...
  4545. </Provider>
  4546. ```
  4547. ### Dark Mode
  4548. ```json
  4549. {
  4550. "fill_body": "#262629",
  4551. "fill_base": "#1a1a1a",
  4552. "fill_tap": "#2b2b2b",
  4553. "fill_grey": "#0a0a0a",
  4554. "color_text_base": "#e6e6e6",
  4555. "color_text_placeholder": "#4d4d4d",
  4556. "border_color_base": "#2b2b2b",
  4557. "border_color_thin": "#2b2b2b",
  4558. }
  4559. ```
  4560. ### How to activate component vibration?
  4561. Since the vibration engines of different platforms are different, we expose the vibration events and execute them by the plug-in engine.
  4562. Usually, the `expo-haptics` engine is used in Expo; the `react-native-haptic-feedback` engine is used in React-Native-CLI;
  4563. Here we take Expo CLI as an example
  4564. ```jsx
  4565. import * as Haptics from 'expo-haptics'
  4566. import { Platform } from 'react-native'
  4567. <Provider
  4568. onHaptics={() => Platform.OS !== 'web' && Haptics.impactAsync('light')}
  4569. >
  4570. ...
  4571. </Provider>
  4572. ```
  4573. ---
  4574. ## Radio
  4575. Source: https://rn.mobile.ant.design/components/radio.md
  4576. # Radio
  4577. Radio.
  4578. ## Examples
  4579. ```tsx
  4580. import { Button, Flex, List, Radio, WingBlank } from '@ant-design/react-native'
  4581. import React from 'react'
  4582. import { ScrollView } from 'react-native'
  4583. const RadioItem = Radio.RadioItem
  4584. type RadioValue = string | number
  4585. interface EventRadioGroup {
  4586. target: { value: RadioValue }
  4587. }
  4588. interface EventRadioItem {
  4589. target: { checked: boolean }
  4590. }
  4591. export default class BasicRadioExample extends React.Component<any, any> {
  4592. state = {
  4593. disabled: false,
  4594. part1Value: 1,
  4595. part2Value: 1,
  4596. part3Value: 1,
  4597. }
  4598. toggleDisabled = () => {
  4599. this.setState({
  4600. disabled: !this.state.disabled,
  4601. })
  4602. }
  4603. onChange = (part1Value: any, e: EventRadioItem) => {
  4604. if (e.target.checked) {
  4605. this.setState({ part1Value })
  4606. }
  4607. }
  4608. onGroupChange2 = (e: EventRadioGroup) => {
  4609. this.setState({
  4610. part2Value: e.target.value,
  4611. })
  4612. }
  4613. onGroupChange3 = (e: EventRadioGroup) => {
  4614. this.setState({
  4615. part3Value: e.target.value,
  4616. })
  4617. }
  4618. render() {
  4619. return (
  4620. <ScrollView>
  4621. <List renderHeader="基本用法">
  4622. <List.Item thumb={<Radio>Radio</Radio>} />
  4623. </List>
  4624. <List
  4625. renderHeader="不可用"
  4626. renderFooter={
  4627. <Button type="primary" onPress={this.toggleDisabled}>
  4628. Toggle disabled
  4629. </Button>
  4630. }>
  4631. <List.Item>
  4632. <Flex>
  4633. <Radio defaultChecked={false} disabled={this.state.disabled}>
  4634. Disabled
  4635. </Radio>
  4636. <WingBlank />
  4637. <Radio disabled={this.state.disabled}>Disabled</Radio>
  4638. </Flex>
  4639. </List.Item>
  4640. </List>
  4641. <List renderHeader="RadioItem">
  4642. <RadioItem
  4643. checked={this.state.part1Value === 1}
  4644. onChange={this.onChange.bind(this, 1)}>
  4645. Use Ant Design Component
  4646. </RadioItem>
  4647. <RadioItem
  4648. checked={this.state.part1Value === 2}
  4649. onChange={this.onChange.bind(this, 2)}>
  4650. Use Ant Design Component
  4651. </RadioItem>
  4652. </List>
  4653. <List renderHeader={'单选组合 RadioGroup\n一组互斥的 Radio 配合使用'}>
  4654. <Radio.Group
  4655. onChange={this.onGroupChange2}
  4656. value={this.state.part2Value}
  4657. style={{
  4658. flexDirection: 'row',
  4659. justifyContent: 'space-around',
  4660. paddingVertical: 6,
  4661. }}>
  4662. <Radio value={1}>A</Radio>
  4663. <Radio value={2}>B</Radio>
  4664. <Radio value={3}>C</Radio>
  4665. <Radio value={4}>D</Radio>
  4666. </Radio.Group>
  4667. </List>
  4668. <List
  4669. renderHeader={
  4670. 'Radio.Group 垂直\n垂直的 Radio.Group,配合更多输入框选项'
  4671. }>
  4672. <Radio.Group
  4673. onChange={this.onGroupChange3}
  4674. value={this.state.part3Value}>
  4675. <RadioItem value={1}>Option A</RadioItem>
  4676. <RadioItem value={2}>Option B</RadioItem>
  4677. <RadioItem value={3}>Option C</RadioItem>
  4678. <RadioItem value={4} left>
  4679. More...
  4680. </RadioItem>
  4681. </Radio.Group>
  4682. </List>
  4683. <List
  4684. renderHeader={
  4685. 'Radio.Group 组合 - 配置方式\n可通过配置 options 参数来渲染单选框。'
  4686. }>
  4687. <RadioGroupExample />
  4688. </List>
  4689. </ScrollView>
  4690. )
  4691. }
  4692. }
  4693. const plainOptions = ['Apple', 'Pear', 'Orange']
  4694. const options = [
  4695. { label: 'Apple', value: 'Apple' },
  4696. { label: 'Pear', value: 'Pear' },
  4697. { label: 'Orange', value: 'Orange' },
  4698. ]
  4699. const optionsWithDisabled = [
  4700. { label: 'Apple', value: 'Apple' },
  4701. { label: 'Pear', value: 'Pear' },
  4702. { label: 'Orange', value: 'Orange', disabled: true },
  4703. ]
  4704. class RadioGroupExample extends React.Component {
  4705. state = {
  4706. value1: 'Apple',
  4707. value2: 'Apple',
  4708. value3: 'Apple',
  4709. }
  4710. onChange1 = (e: EventRadioGroup) => {
  4711. console.log('radio1 checked', e.target.value)
  4712. this.setState({
  4713. value1: e.target.value,
  4714. })
  4715. }
  4716. onChange2 = (e: EventRadioGroup) => {
  4717. console.log('radio2 checked', e.target.value)
  4718. this.setState({
  4719. value2: e.target.value,
  4720. })
  4721. }
  4722. onChange3 = (e: EventRadioGroup) => {
  4723. console.log('radio3 checked', e.target.value)
  4724. this.setState({
  4725. value3: e.target.value,
  4726. })
  4727. }
  4728. render() {
  4729. const { value1, value2, value3 } = this.state
  4730. return (
  4731. <>
  4732. <List renderHeader="PlainOptions">
  4733. <Radio.Group
  4734. options={plainOptions}
  4735. onChange={this.onChange1}
  4736. value={value1}
  4737. />
  4738. </List>
  4739. <List renderHeader="Options">
  4740. <Radio.Group
  4741. options={options}
  4742. onChange={this.onChange2}
  4743. value={value2}
  4744. />
  4745. </List>
  4746. <List renderHeader="OptionsWithDisabled">
  4747. <Radio.Group
  4748. options={optionsWithDisabled}
  4749. onChange={this.onChange3}
  4750. value={value3}
  4751. />
  4752. </List>
  4753. </>
  4754. )
  4755. }
  4756. }
  4757. ```
  4758. ## API
  4759. ### Type
  4760. ```ts
  4761. type RadioValue = string | number
  4762. ```
  4763. ### Radio
  4764. Properties | Descrition | Type | Default
  4765. -----------|------------|------|--------
  4766. | defaultChecked | the initial checked state | Boolean | - |
  4767. | checked | to set the current checked state | Boolean | - |
  4768. | disabled | whether disabled | Boolean | false |
  4769. | onChange | a callback function, can be executed when the checked state changes | (e: { target: { checked: boolean } }) => void | - |
  4770. | value | Value is carrying identification, used in `Group` mode | `RadioValue` | - |
  4771. ### Radio.RadioItem
  4772. The encapsulation about `Radio` based on `List.Item`, the property `extra` of `List.Item` will be passed to `Radio`, while other properties remain the same.
  4773. Other APIs are identical with `Radio`.
  4774. ### Radio.Group `v5.0.0`
  4775. Radio group can wrap a group of `Radio`。
  4776. ```ts
  4777. type Event = { target: { value: RadioValue } }
  4778. ```
  4779. Properties | Descrition | Type | Default
  4780. ----|-----|------|------
  4781. | defaultValue | Default selected value | `RadioValue` | - |
  4782. | disabled | Disable all radio buttons | Boolean | false |
  4783. | options | Set children optional | `string[]` \| `number[]` \| `Array<{ label: string value: string disabled?: boolean }>` | - |
  4784. | value | Used for setting the currently selected value | `RadioValue` | - |
  4785. | onChange | The callback function that is triggered when the state changes | (e: `Event`) => void | - |
  4786. ---
  4787. ## Result
  4788. Source: https://rn.mobile.ant.design/components/result.md
  4789. # Result
  4790. Result page contains feedback like illustrations, icons and text.
  4791. ### Rules
  4792. - Use for significant feedback like payment success or network failure.
  4793. - Improve brand value with beautiful illustrations.
  4794. - Provide obvious operation point for error type result page, eg: reload page.
  4795. ## Examples
  4796. ```tsx
  4797. import { Result } from '@ant-design/react-native'
  4798. import React from 'react'
  4799. import { Image, ScrollView, Text } from 'react-native'
  4800. export default class ResultExample extends React.Component<any, any> {
  4801. render() {
  4802. return (
  4803. <ScrollView style={{ backgroundColor: '#F5F5F9', flex: 1 }}>
  4804. <Text style={{ margin: 10, color: '#999' }}>URI 图片</Text>
  4805. <Result
  4806. imgUrl={{
  4807. uri: 'https://zos.alipayobjects.com/rmsportal/GcBguhrOdlYvGfnsXgrE.png',
  4808. }}
  4809. title="验证成功"
  4810. message="所提交内容已成功完成验证"
  4811. />
  4812. <Text style={{ margin: 10, color: '#999' }}>Image source</Text>
  4813. <Result
  4814. imgUrl={require('./alipay.png')}
  4815. title="验证成功"
  4816. message="所提交内容已成功完成验证"
  4817. />
  4818. <Text style={{ margin: 10, color: '#999' }}>Image element</Text>
  4819. <Result
  4820. img={
  4821. <Image
  4822. source={require('./alipay.png')}
  4823. style={{ width: 60, height: 60 }}
  4824. />
  4825. }
  4826. title="验证成功"
  4827. message={<Text>所提交内容已成功完成验证</Text>}
  4828. />
  4829. <Text style={{ margin: 10, color: '#999' }}>含 button 操作</Text>
  4830. <Result
  4831. img={
  4832. <Image
  4833. source={require('./alipay.png')}
  4834. style={{ width: 60, height: 60 }}
  4835. />
  4836. }
  4837. title="验证成功"
  4838. message="所提交内容已成功完成验证"
  4839. buttonText="完成"
  4840. buttonType="primary"
  4841. onButtonClick={(e: any) => alert(e.toString())}
  4842. />
  4843. </ScrollView>
  4844. )
  4845. }
  4846. }
  4847. ```
  4848. ## API
  4849. Properties | Descrition | Type | Default
  4850. -----------|------------|------|--------
  4851. imgUrl | image url | string / Image Source(rn) | -
  4852. img | image node (could be `<img src="" />` or `<Icon type="" />`), which will override `imgUrl` | ReactNode | -
  4853. title | title of result page | ReactNode | -
  4854. message | message text of result page | ReactNode | -
  4855. buttonText | text of built-in button | string | -
  4856. buttonType | type of built-in button | string | -
  4857. onButtonClick | callback of clicking built-in button | (e: Object): void | -
  4858. ---
  4859. ## SearchBar
  4860. Source: https://rn.mobile.ant.design/components/search-bar.md
  4861. # SearchBar
  4862. Normally located below NavBar, the activation status is exited by the Cancel button.
  4863. ### Rules
  4864. - Should fill some text in placeholder to remind the user to enter the relevant content, such as: "双11特卖".
  4865. - Below the SearchBar, you can provide useful labels copy to help users complete the input directly by clicking, such as: List some of the most recent search keywords.
  4866. ## Examples
  4867. ```tsx
  4868. import { SearchBar } from '@ant-design/react-native'
  4869. import React from 'react'
  4870. import { Alert, View } from 'react-native'
  4871. export default class SearchBarDemo extends React.Component<any, any> {
  4872. state = {
  4873. value: '美食',
  4874. }
  4875. onChange = (value: any) => {
  4876. this.setState({ value })
  4877. }
  4878. clear = () => {
  4879. this.setState({ value: '' })
  4880. }
  4881. render() {
  4882. return (
  4883. <View style={{ marginTop: 30 }}>
  4884. <SearchBar defaultValue="初始值" placeholder="搜索" />
  4885. <SearchBar
  4886. value={this.state.value}
  4887. placeholder="搜索"
  4888. onSubmit={(value: any) => Alert.alert(value)}
  4889. onCancel={this.clear}
  4890. onChange={this.onChange}
  4891. showCancelButton
  4892. />
  4893. </View>
  4894. )
  4895. }
  4896. }
  4897. ```
  4898. ## API
  4899. Properties | Descrition | Type | Default
  4900. -----------|------------|------|--------
  4901. | defaultValue | the uncontrolled default value | String | |
  4902. | value | the controlled current value | String | |
  4903. | placeholder | placeholder | String | |
  4904. | onSubmit | submit event (click the enter on the keyboard) | (val: string): void | |
  4905. | onChange | change event callback | (val: string): void | |
  4906. | onFocus | focus event callback | (): void | |
  4907. | onBlur | blur event callback | (): void | |
  4908. | onCancel | Click the `Cancel` button to trigger (The text of the input box is no longer automatically cleared) | (val: string): void | |
  4909. | showCancelButton | Whether the `Cancel` button is always displayed | bool | `false` |
  4910. | cancelText | Customize the text of the `Cancel` button | String | `取消` |
  4911. | disabled | Set disabled | bool | `false` |
  4912. Note: RN version more API please refer to [http://facebook.github.io/react-native/docs/textinput.html](http://facebook.github.io/react-native/docs/textinput.html)
  4913. ---
  4914. ## SegmentedControl
  4915. Source: https://rn.mobile.ant.design/components/segmented-control.md
  4916. # SegmentedControl
  4917. Deprecated since `5.2.1`.
  4918. Please use [@react-native-community/segmented-control](https://github.com/react-native-community/segmented-control#usage) instead.
  4919. ---
  4920. ## Slider
  4921. Source: https://rn.mobile.ant.design/components/slider.md
  4922. # Slider
  4923. A Slider component for selecting particular value in range, eg: controls the display brightness of the screen.
  4924. ### Rule
  4925. - By default, the minimum value in the left and maximum value in the right of `Slider` .
  4926. - Generally `Slider` is positioned horizontally.
  4927. ## Examples
  4928. ```tsx
  4929. import { List, Provider, Slider, Switch, Toast } from '@ant-design/react-native'
  4930. import React, { useEffect, useState } from 'react'
  4931. import { ScrollView } from 'react-native'
  4932. export default function StepperExample() {
  4933. useEffect(() => {
  4934. Toast.config({ stackable: false })
  4935. }, [])
  4936. const [disabledStep, setDisabledStep] = useState(false)
  4937. const [tapToSeek, setTapToSeek] = useState(true)
  4938. const marks = {
  4939. 0: 0,
  4940. // 20: 20,
  4941. 40: 40,
  4942. 60: '',
  4943. 80: 80,
  4944. 100: 100,
  4945. }
  4946. const toastValue = (value: number | [number, number]) => {
  4947. let text = ''
  4948. if (typeof value === 'number') {
  4949. text = `${value}`
  4950. } else {
  4951. text = `[${value.join(',')}]`
  4952. }
  4953. Toast.show({ content: `当前选中值为:${text}`, position: 'top' })
  4954. }
  4955. return (
  4956. <Provider>
  4957. <ScrollView>
  4958. <List>
  4959. <List.Item
  4960. extra={
  4961. <Switch
  4962. checked={disabledStep}
  4963. onChange={(val) => {
  4964. setDisabledStep(val)
  4965. }}
  4966. />
  4967. }>
  4968. Disabled Step
  4969. <List.Item.Brief>
  4970. 是否禁用步距;禁用后`onChange`将返回带有小数点的值
  4971. </List.Item.Brief>
  4972. </List.Item>
  4973. <List.Item
  4974. extra={
  4975. <Switch
  4976. checked={tapToSeek}
  4977. onChange={(val) => {
  4978. setTapToSeek(val)
  4979. }}
  4980. />
  4981. }>
  4982. Tap To Seek
  4983. <List.Item.Brief>
  4984. 是否允许点击滑块轨道来设置slider值
  4985. </List.Item.Brief>
  4986. </List.Item>
  4987. </List>
  4988. <List
  4989. renderHeader={'基础用法'}
  4990. onStartShouldSetResponder={() => true}
  4991. onTouchStart={(e) => e.stopPropagation()}>
  4992. <List.Item>
  4993. <Slider
  4994. max={1}
  4995. disabledStep={disabledStep}
  4996. tapToSeek={tapToSeek}
  4997. onChange={toastValue}
  4998. onAfterChange={toastValue}
  4999. onSlidingStart={(val, index) =>
  5000. console.log('onSlidingStart', { val, index })
  5001. }
  5002. onSlidingComplete={(val, index) =>
  5003. console.log('onSlidingComplete', { val, index })
  5004. }
  5005. />
  5006. </List.Item>
  5007. </List>
  5008. <List renderHeader={'显示刻度(ticks)并指定步距(step)'}>
  5009. <List.Item>
  5010. <Slider
  5011. ticks
  5012. step={10}
  5013. defaultValue={40}
  5014. disabledStep={disabledStep}
  5015. tapToSeek={tapToSeek}
  5016. />
  5017. </List.Item>
  5018. </List>
  5019. <List renderHeader={'传入刻度标记(marks)'}>
  5020. <List.Item>
  5021. <Slider
  5022. marks={marks}
  5023. ticks
  5024. disabledStep={disabledStep}
  5025. tapToSeek={tapToSeek}
  5026. />
  5027. </List.Item>
  5028. </List>
  5029. <List renderHeader={'最大(max)/最小值(min)'}>
  5030. <List.Item>
  5031. <Slider
  5032. step={100}
  5033. min={100}
  5034. max={1000}
  5035. ticks
  5036. onAfterChange={toastValue}
  5037. disabledStep={disabledStep}
  5038. tapToSeek={tapToSeek}
  5039. />
  5040. </List.Item>
  5041. </List>
  5042. <List renderHeader={'双滑块(range)'}>
  5043. <List.Item>
  5044. <Slider
  5045. marks={marks}
  5046. ticks
  5047. range
  5048. defaultValue={[60, 40]}
  5049. disabledStep={disabledStep}
  5050. tapToSeek={tapToSeek}
  5051. />
  5052. </List.Item>
  5053. </List>
  5054. <List renderHeader={'在拖动时显示悬浮提示'}>
  5055. <List.Item>
  5056. <Slider popover disabledStep={disabledStep} tapToSeek={tapToSeek} />
  5057. </List.Item>
  5058. </List>
  5059. </ScrollView>
  5060. </Provider>
  5061. )
  5062. }
  5063. ```
  5064. ## API
  5065. | Properties | Description | Type | Default | Version |
  5066. | --- | --- | --- | --- | --- |
  5067. | defaultValue | Default value | `number` \|<br/> `[number, number]` | `range ? [0, 0] : 0` | |
  5068. | disabled | Whether disabled | `boolean` | `false` | |
  5069. | disabledStep | Whether disabled step; if `true`, `onChange` will return a value with a decimal point | `boolean` | `false` | `5.3.0` |
  5070. | icon | The thumb icon of slider | `ReactNode` | - | |
  5071. | marks | Tick marks | `{ [key: number]: React.ReactNode }` | - | `5.2.1` |
  5072. | max | Max value | `number` | `100` | |
  5073. | min | Min value | `number` | `0` | |
  5074. | onAfterChange | Consistent with the trigger timing of `touchend`, pass the current value as a parameter | `(value: number | [number, number]) => void` | - | |
  5075. | onChange | Triggered when the slider is dragged, and the current dragged value is passed in as a parameter | `(value: number | [number, number]) => void` | - | |
  5076. | onSlidingStart | Callback that is called when the user picks up the slider.<br/>The initial value is passed as an argument to the callback handler. | `(value: number | [number, number], index: number) => void` | - | `5.3.0` |
  5077. | onSlidingComplete | Callback that is called when the user releases the slider, regardless if the value has changed.<br/>The current value is passed as an argument to the callback handler. | `(value: number | [number, number], index: number) => void` | - | `5.3.0` |
  5078. | popover | Whether to display the popover when dragging. Support passing in function to customize the rendering content. | `boolean | ((value: number) => ReactNode)` | `false` | `5.2.1` |
  5079. | residentPopover | Whether the `popover` is permanently displayed , this attribute takes effect when `popover` exists | `boolean ` | `false` | `5.2.1` |
  5080. | range | Whether it is a double sliders | `boolean` | `false` | `5.2.1` |
  5081. | step | Step distance, the value must be greater than `0`, and `(max-min)` can be divisible by `step`. When `marks` is not null, the configuration of `step` is invalid | `number` | `1` | `5.2.1` |
  5082. | style | Container style | `StyleProp<ViewStyle>` | - | |
  5083. | styles | Semantic DOM style | [SliderStyle](#sliderstyle-interface) | - | `5.2.1` |
  5084. | tapToSeek | Permits tapping on the slider track to set the thumb icon position. | `boolean` | `true` | `5.3.0` |
  5085. | ticks | Whether to display the scale | `boolean` | `false` | `5.2.1` |
  5086. | value | Current value | `number` \|<br/> `[number, number]` | - | |
  5087. > The returned `value` format is `[number, number]` when `range={true}`, otherwise it is `number`.
  5088. ### SliderStyle interface
  5089. ```typescript
  5090. interface SliderStyle {
  5091. // Same as `style`
  5092. slider: ViewStyle // belongs to PanGesture area when `range=false`
  5093. disabled: ViewStyle
  5094. // Track
  5095. trackContianer: ViewStyle // track container
  5096. track: ViewStyle // track line
  5097. fill: ViewStyle // Filled portion of the track line
  5098. // Track button wrap + shadow style
  5099. thumb: ViewStyle
  5100. // Tick
  5101. ticks: ViewStyle
  5102. tick: ViewStyle
  5103. tickActive: ViewStyle
  5104. // Mark within the tick
  5105. mark: ViewStyle
  5106. markText: TextStyle
  5107. }
  5108. ```
  5109. ---
  5110. ## Stepper
  5111. Source: https://rn.mobile.ant.design/components/stepper.md
  5112. # Stepper
  5113. `Stepper` can be used to increase or decrease value step by step.
  5114. ### Rule
  5115. - When you want to make small adjustments to the value, you can use `Stepper`. eg: Adjust the annual return from 4.00% to 4.05%.
  5116. ## Examples
  5117. ```tsx
  5118. import { List, Provider, Stepper, Toast } from '@ant-design/react-native'
  5119. import React from 'react'
  5120. import { KeyboardAvoidingView, Platform, ScrollView } from 'react-native'
  5121. export default function StepperExample() {
  5122. return (
  5123. <Provider>
  5124. <KeyboardAvoidingView
  5125. behavior="padding"
  5126. keyboardVerticalOffset={Platform.OS === 'ios' ? 100 : undefined}>
  5127. <ScrollView>
  5128. <List renderHeader={'基础用法'}>
  5129. <List.Item
  5130. extra={
  5131. <Stepper
  5132. defaultValue={1}
  5133. onChange={(value) => {
  5134. console.log(value)
  5135. }}
  5136. />
  5137. }>
  5138. 基础用法
  5139. </List.Item>
  5140. <List.Item extra={<Stepper step={10} defaultValue={10} />}>
  5141. 步长设置
  5142. </List.Item>
  5143. <List.Item extra={<Stepper min={-5} max={5} />}>
  5144. 限制输入范围
  5145. </List.Item>
  5146. <List.Item extra={<Stepper digits={1} />}>
  5147. 格式化到一位小数
  5148. </List.Item>
  5149. <List.Item
  5150. extra={
  5151. <Stepper
  5152. defaultValue={93}
  5153. formatter={(value) => `$ ${value}`}
  5154. parser={(text) => parseFloat(text.replace('$', ''))}
  5155. onChange={(value) => {
  5156. console.log(value, typeof value)
  5157. }}
  5158. />
  5159. }>
  5160. 自定义格式
  5161. </List.Item>
  5162. </List>
  5163. <List renderHeader={'状态/样式'}>
  5164. <List.Item extra={<Stepper disabled />}>禁用状态</List.Item>
  5165. <List.Item extra={<Stepper readOnly />}>输入框只读状态</List.Item>
  5166. <List.Item
  5167. extra={
  5168. <Stepper
  5169. onFocus={() => {
  5170. Toast.info('获得焦点')
  5171. }}
  5172. onBlur={() => {
  5173. Toast.info('失去焦点')
  5174. }}
  5175. />
  5176. }>
  5177. 获得/失去焦点
  5178. </List.Item>
  5179. <List.Item
  5180. extra={
  5181. <Stepper
  5182. allowEmpty={true}
  5183. min={10}
  5184. max={20}
  5185. onChange={(value) => {
  5186. console.log(value)
  5187. }}
  5188. />
  5189. }>
  5190. 允许清空
  5191. </List.Item>
  5192. <List.Item extra={<Stepper defaultValue={10000} step={10000} />}>
  5193. 自定义样式
  5194. </List.Item>
  5195. </List>
  5196. <StringModeExample />
  5197. </ScrollView>
  5198. </KeyboardAvoidingView>
  5199. </Provider>
  5200. )
  5201. }
  5202. const StringModeExample = () => {
  5203. const [value, setValue] = React.useState('9999999999999999')
  5204. return (
  5205. <List renderHeader={'stringMode'}>
  5206. <List.Item>
  5207. <Stepper
  5208. stringMode
  5209. defaultValue="0.000000000000002"
  5210. step="0.000000000000001"
  5211. onChange={console.log}
  5212. style={{ width: '100%' }}
  5213. />
  5214. </List.Item>
  5215. <List renderHeader={'stringMode control'}>
  5216. <List.Item>
  5217. <Stepper
  5218. stringMode
  5219. value={value}
  5220. step="13579"
  5221. onChange={setValue}
  5222. style={{ width: '100%' }}
  5223. />
  5224. </List.Item>
  5225. </List>
  5226. </List>
  5227. )
  5228. }
  5229. ```
  5230. ## API
  5231. | Name | Description | Type | Default | Version |
  5232. | --- | --- | --- | --- | --- |
  5233. | allowEmpty | Whether to allow empty content. | `boolean` | `false` |
  5234. | defaultValue | Default value | `number \| null` | `0` |
  5235. | digits | Format to a fixed number of digits after the decimal point, set to `0` means format to integer. Will use `formatter` as display value when configured | `number` | - | 5.2.1 |
  5236. | disabled | Whether to disabled Stepper | `boolean` | `false` |
  5237. | formatter | Format value in input | `(value?: number) => string` | - | 5.2.1 |
  5238. | inputStyle | TextInput style | `StyleProp<TextStyle>` | - |
  5239. | max | Max value | `number` | - |
  5240. | min | Min value | `number` | - |
  5241. | minusButtonProps | The minus button props | [TouchableHighlightProps](https://reactnative.dev/docs/touchablehighlight) | `{ activeOpacity:1, underlayColor:'#ddd', children: <Text>-</Text>, delayLongPress:500 }` | 5.2.1 |
  5242. | plusButtonProps | The plus button props | [TouchableHighlightProps](https://reactnative.dev/docs/touchablehighlight) | `{ activeOpacity:1, underlayColor:'#ddd', children: <Text>+</Text>, delayLongPress:500 }` | 5.2.1 |
  5243. | onChange | Callback when value is changed | `(value: number \| null) => void` | - |
  5244. | parser | Parse input text into number which should work with `formatter` | `(text: string) => number` | - | 5.2.1 |
  5245. | step | The value to increase or decrease each time, can be a decimal | `number` | `1` |
  5246. | stringMode | Set value as string to support high precision decimals. Will set `defaultValue`,`value`, `min`, `max`, `onChange` to `string` type | `boolean` | `false` | 5.2.1 |
  5247. | styles | Semantic DOM style | [StepperStyle](#stepperstyle-interface) | - | 5.2.1 |
  5248. | value | Current number, controlled value | `number \| null` | - |
  5249. - New in `5.2.1`. In addition, all properties of react-native [TextInput](http://facebook.github.io/react-native/docs/textinput.html) are supported, eg: **`readOnly`** **`onFocus`** **`onBlur`**
  5250. - New in `5.2.1`. Support **Long Press To Trigger** increment or decrement; customizable execution timing: `plusButtonProps={{ delayLongPress: 500 }}`.
  5251. - When `allowEmpty` is `true`, the `value` parameter of `onChange` may be **`null`**, please pay attention when using it.
  5252. ### StepperStyle interface
  5253. `5.2.1`refactored the styles
  5254. ```typescript
  5255. export interface StepperStyle extends Partial<InputStyle> {
  5256. // extends InputStyle
  5257. container: ViewStyle
  5258. input: ViewStyle
  5259. prefix: ViewStyle // for minus button
  5260. suffix: ViewStyle // for plus button
  5261. // StepperStyle
  5262. inputDisabled: TextStyle
  5263. stepWrap: ViewStyle // step button wrap
  5264. stepText: TextStyle // step button text
  5265. stepDisabled: ViewStyle // step button disabled
  5266. disabledStepTextColor: TextStyle
  5267. }
  5268. ```
  5269. ## Ref
  5270. Same as [component/Input](/components/input#ref)
  5271. ---
  5272. ## Steps
  5273. Source: https://rn.mobile.ant.design/components/steps.md
  5274. # Steps
  5275. Steps is typically used for displaying the progress of a task, or guiding users through the steps of a complex flow.
  5276. ### Rules
  5277. - Suitable for step-by-step and long-lasting task, e.g. the process of transfer accounts. If the task is continuous and short, such as opening a page, component `Progress` will fit better.
  5278. - When the task is complicated or has a certain sequence in the series of subtasks, we can decompose it into several steps to make things easier, e.g. register new account.
  5279. ## Examples
  5280. ```tsx
  5281. import { Icon, Steps, WingBlank } from '@ant-design/react-native'
  5282. import React from 'react'
  5283. import { ScrollView, Text, View } from 'react-native'
  5284. const Step = Steps.Step
  5285. export default class BasicTimelineExample extends React.Component<any, any> {
  5286. constructor(props: any) {
  5287. super(props)
  5288. this.state = {
  5289. steps1: [
  5290. { title: 'Finished', description: 'This is description' },
  5291. { title: 'In Progress', description: 'This is description' },
  5292. { title: 'Waiting', description: 'This is description' },
  5293. ],
  5294. steps2: [
  5295. {
  5296. title: 'Finished',
  5297. description: 'This is description',
  5298. status: 'finish',
  5299. },
  5300. {
  5301. title: 'In Progress',
  5302. description: 'This is description',
  5303. status: 'process',
  5304. },
  5305. {
  5306. title: 'Waiting',
  5307. description: 'This is description',
  5308. status: 'error',
  5309. },
  5310. {
  5311. title: 'Waiting',
  5312. description: 'This is description',
  5313. status: 'wait',
  5314. },
  5315. ],
  5316. }
  5317. }
  5318. render() {
  5319. return (
  5320. <ScrollView
  5321. style={{ flex: 1 }}
  5322. automaticallyAdjustContentInsets={false}
  5323. showsHorizontalScrollIndicator={false}
  5324. showsVerticalScrollIndicator={false}>
  5325. <View style={{ marginTop: 60 }}>
  5326. <WingBlank size="lg">
  5327. <Steps size="small" current={1} direction="horizontal">
  5328. {this.state.steps1.map((item: any, index: any) => (
  5329. <Step
  5330. key={index}
  5331. title={
  5332. <View>
  5333. <Text>title:{item.title}</Text>
  5334. </View>
  5335. }
  5336. status={item.status}
  5337. />
  5338. ))}
  5339. </Steps>
  5340. </WingBlank>
  5341. </View>
  5342. <View style={{ marginTop: 60 }}>
  5343. <WingBlank size="lg">
  5344. <Steps size="small" current={1}>
  5345. {this.state.steps1.map((item: any, index: any) => (
  5346. <Step
  5347. key={index}
  5348. title={
  5349. <View>
  5350. <Text>title:{item.title}</Text>
  5351. </View>
  5352. }
  5353. description={
  5354. <View>
  5355. <Text>desc:{item.description}</Text>
  5356. </View>
  5357. }
  5358. status={item.status}
  5359. />
  5360. ))}
  5361. </Steps>
  5362. </WingBlank>
  5363. </View>
  5364. <View>
  5365. <WingBlank size="lg">
  5366. <Steps size="small">
  5367. {this.state.steps2.map((item: any, index: any) => (
  5368. <Step
  5369. key={index}
  5370. title={item.title}
  5371. description={item.description}
  5372. status={item.status}
  5373. />
  5374. ))}
  5375. </Steps>
  5376. </WingBlank>
  5377. </View>
  5378. <View>
  5379. <WingBlank size="lg">
  5380. <Steps current={1}>
  5381. {this.state.steps1.map((item: any, index: any) => (
  5382. <Step
  5383. key={index}
  5384. title={item.title}
  5385. description={item.description}
  5386. status={item.status}
  5387. />
  5388. ))}
  5389. </Steps>
  5390. </WingBlank>
  5391. </View>
  5392. <View>
  5393. <WingBlank size="lg">
  5394. <Steps>
  5395. {this.state.steps2.map((item: any, index: any) => (
  5396. <Step
  5397. key={index}
  5398. title={item.title}
  5399. description={item.description}
  5400. status={item.status}
  5401. />
  5402. ))}
  5403. </Steps>
  5404. </WingBlank>
  5405. </View>
  5406. <View>
  5407. <WingBlank size="lg">
  5408. <Steps current={1}>
  5409. <Step
  5410. key={0}
  5411. title="Finished"
  5412. description="This is description"
  5413. status="finish"
  5414. />
  5415. <Step
  5416. key={1}
  5417. title="Progress"
  5418. description="This is description"
  5419. status="progress"
  5420. />
  5421. <Step
  5422. key={2}
  5423. title="Wait"
  5424. description="This is description"
  5425. status="wait"
  5426. icon={<Icon name="down" size={20} color="white" />}
  5427. />
  5428. </Steps>
  5429. </WingBlank>
  5430. </View>
  5431. <View>
  5432. <WingBlank size="lg">
  5433. <Steps current={1}>
  5434. <Step
  5435. key={0}
  5436. title="Finished"
  5437. description="This is description"
  5438. status="finish"
  5439. renderIcon={({ starting, waiting, error }) => {
  5440. let icon
  5441. if (starting) {
  5442. icon = <Icon name="home" />
  5443. } else if (waiting) {
  5444. icon = <Icon name="user" />
  5445. } else if (error) {
  5446. icon = <Icon name="star" />
  5447. }
  5448. return icon
  5449. }}
  5450. />
  5451. <Step
  5452. key={1}
  5453. title="Progress"
  5454. description="This is description"
  5455. status="progress"
  5456. renderIcon={({ starting, waiting, error }) => {
  5457. let icon
  5458. if (starting) {
  5459. icon = <Icon name="home" />
  5460. } else if (waiting) {
  5461. icon = <Icon name="user" />
  5462. } else if (error) {
  5463. icon = <Icon name="star" />
  5464. }
  5465. return icon
  5466. }}
  5467. />
  5468. <Step
  5469. key={2}
  5470. title="Wait"
  5471. description="This is description"
  5472. status="wait"
  5473. renderIcon={({ starting, waiting, error }) => {
  5474. let icon
  5475. if (starting) {
  5476. icon = <Icon name="home" />
  5477. } else if (waiting) {
  5478. icon = <Icon name="user" />
  5479. } else if (error) {
  5480. icon = <Icon name="star" />
  5481. }
  5482. return icon
  5483. }}
  5484. />
  5485. <Step
  5486. key={3}
  5487. title="Wait"
  5488. description="This is description"
  5489. status="error"
  5490. renderIcon={({ starting, waiting, error }) => {
  5491. let icon
  5492. if (starting) {
  5493. icon = <Icon name="home" />
  5494. } else if (waiting) {
  5495. icon = <Icon name="user" />
  5496. } else if (error) {
  5497. icon = <Icon name="star" />
  5498. }
  5499. return icon
  5500. }}
  5501. />
  5502. </Steps>
  5503. </WingBlank>
  5504. </View>
  5505. </ScrollView>
  5506. )
  5507. }
  5508. }
  5509. ```
  5510. ## API
  5511. ```jsx
  5512. <Steps>
  5513. <Step title="First" />
  5514. <Step title="Second" />
  5515. <Step title="Third" />
  5516. </Steps>
  5517. ```
  5518. ### Steps
  5519. The Steps container.
  5520. | Properties | Descrition | Type | Default |
  5521. | ---------- | -------------------------------------------------------------------------------------------------- | --------------------------------- | ---------- |
  5522. | current | To set the current step, counting from 0. You can overwrite this state by using `status` of `Step` | number | `0` |
  5523. | size | To specify the size of the step bar, a smaller size can be achieved by setting it to `small` | string | - |
  5524. | direction | To specify the direction of the step bar(now only support `vertical` for react-native) | Enum { 'vertical', 'horizontal' } | `vertical` |
  5525. ### Steps.Step
  5526. A single step used as child component of the Step.
  5527. | Properties | Descrition | Type | Default |
  5528. | ----------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ------- |
  5529. | status | To specify the status. It will be automatically set by `current` of `Steps` if not configured. | Enum { 'wait', 'process', 'finish', 'error' } | `wait` |
  5530. | title | Title of the step | React.Element | - |
  5531. | description | Detail of the step(optional property) | React.Element | - |
  5532. | icon | Icon of the step(optional property) | object/React.Element | - |
  5533. | renderIcon | customize step icon(optional) | (params: { starting: boolean; waiting: boolean; error: boolean; }) => React.ReactNode | - |
  5534. ---
  5535. ## SwipeAction
  5536. Source: https://rn.mobile.ant.design/components/swipe-action.md
  5537. # SwipeAction
  5538. iOS-style swipeout buttons that appear from behind a component.
  5539. ### Definition
  5540. Call out operations from one side of screen with gesture.
  5541. ### Rules
  5542. 1. Only one row can be swiped at a time.
  5543. 2. Can hide operations by clicking outside of buttons or swiping the list backforwards.
  5544. ## Examples
  5545. ```tsx
  5546. import { List, SwipeAction } from '@ant-design/react-native'
  5547. import React from 'react'
  5548. import { View } from 'react-native'
  5549. export default class BasicSwipeActionExample extends React.Component<any, any> {
  5550. asyncFunction = () => {
  5551. return new Promise((resolve) => {
  5552. setTimeout(() => {
  5553. console.log('asd')
  5554. resolve(123)
  5555. }, 1500)
  5556. })
  5557. }
  5558. render() {
  5559. const right = [
  5560. {
  5561. text: 'More',
  5562. onPress: async () => {
  5563. await this.asyncFunction()
  5564. },
  5565. backgroundColor: 'orange',
  5566. color: 'white',
  5567. },
  5568. {
  5569. text: 'Delete',
  5570. onPress: () => console.log('delete'),
  5571. backgroundColor: 'red',
  5572. color: 'white',
  5573. },
  5574. ]
  5575. const left = [
  5576. {
  5577. text: 'Read',
  5578. onPress: () => console.log('read'),
  5579. backgroundColor: 'blue',
  5580. color: 'white',
  5581. },
  5582. {
  5583. text: 'Reply',
  5584. onPress: () => console.log('reply'),
  5585. backgroundColor: 'green',
  5586. color: 'white',
  5587. },
  5588. ]
  5589. return (
  5590. <View style={{ paddingTop: 30 }}>
  5591. <List>
  5592. <SwipeAction
  5593. right={right}
  5594. left={left}
  5595. closeOnAction
  5596. closeOnTouchOutside>
  5597. <List.Item extra="extra content">
  5598. Simple example: left and right buttons
  5599. </List.Item>
  5600. </SwipeAction>
  5601. </List>
  5602. <List>
  5603. <SwipeAction
  5604. right={right}
  5605. left={left}
  5606. closeOnAction={false}
  5607. closeOnTouchOutside
  5608. onSwipeableOpen={() => console.log('open')}
  5609. onSwipeableClose={() => console.log('close')}>
  5610. <List.Item extra="extra content">
  5611. Simple example: left and right buttons
  5612. </List.Item>
  5613. </SwipeAction>
  5614. </List>
  5615. </View>
  5616. )
  5617. }
  5618. }
  5619. ```
  5620. ## API
  5621. ### SwipeAction
  5622. | Properties | Descrition | Type | Default | Version |
  5623. |-----|-----|------|-------|------|
  5624. | closeOnAction | Whether to return to the position automatically when the operation button is clicked | `boolean` | `true` | `5.2.1` |
  5625. | closeOnTouchOutside | Whether to return to the position automatically when other areas is clicked | `boolean` | `false` | `5.2.1` |
  5626. | left | List of operation buttons on the left | [SwipeoutButtonProps](/components/swipe-action#swipeoutbuttonprops)[] | `[]` | |
  5627. | right | List of operation buttons on the right | [SwipeoutButtonProps](/components/swipe-action#swipeoutbuttonprops)[] | `[]` | |
  5628. | styles | Semantic DOM style | [SwipeActionStyle](/components/swipe-action#swipeactionstyle-interface) | - | `5.2.1` |
  5629. The rest of the props of `SwipeAction` are exactly the same as [react-native-gesture-handler/Swipeable](https://docs.swmansion.com/react-native-gesture-handler/docs/components/swipeable/),
  5630. **eg: `onSwipeableOpen` , `onSwipeableClose` , `renderLeftActions` , `renderRightActions`**
  5631. When you set `renderLeftActions` prop, it will override `left` prop; <br/>
  5632. when you set `renderRightActions` prop, it will override `right` prop.
  5633. ### SwipeoutButtonProps
  5634. | Properties | Descrition | Type | Default | Version |
  5635. |-----|------|------|------|------|
  5636. | backgroundColor | background color | `string` | - | |
  5637. | color | font color | `string` | - | |
  5638. | disabled | Whether disabled | `boolean` | - | |
  5639. | onPress | Trigger when clicked | `() => void | Promise<any>` | - | `5.2.1` support async |
  5640. | style | Aaction button style, effective when `text` is `string` | `StyleProp<TextStyle>` | - | |
  5641. | text | Text | `string | ReactNode` | - | |
  5642. | actionButtonProps | Rest props | [RectButtonProps](https://docs.swmansion.com/react-native-gesture-handler/docs/components/buttons/#rectbutton) | - | `5.2.1` |
  5643. ### SwipeActionStyle interface
  5644. ```typescript
  5645. export interface SwipeActionStyle {
  5646. actionButton: ViewStyle
  5647. actionText: TextStyle
  5648. }
  5649. ```
  5650. ### Ref
  5651. New in `5.2.1`. Ref to Swipeable[#Ref](https://docs.swmansion.com/react-native-gesture-handler/docs/components/swipeable/#methods)
  5652. | Properties | Descrition | Type|
  5653. |-----|------|------|
  5654. | close | method that closes component | `() => void` |
  5655. | openLeft | method that opens component on left side. | `() => void` |
  5656. | openRight | method that opens component on right side. | `() => void` |
  5657. | reset | method that resets the swiping states of this `Swipeable` component.<br/>Unlike method `close`, this method does not trigger any animation. | `() => void` |
  5658. ---
  5659. ## Switch
  5660. Source: https://rn.mobile.ant.design/components/switch.md
  5661. # Switch
  5662. Select between two status, e.g. Select On or Off.
  5663. ### Rules
  5664. - This is a **controlled component** that requires an `onChange` callback that updates the `checked` prop in order for the component to reflect user actions.
  5665. ## Examples
  5666. ```tsx
  5667. import { Button, Icon, List, Switch, WhiteSpace, WingBlank } from '@ant-design/react-native'
  5668. import React from 'react'
  5669. import { ScrollView } from 'react-native'
  5670. export default class SwitchExample extends React.Component<any, any> {
  5671. constructor(props: any) {
  5672. super(props)
  5673. this.state = {
  5674. disabled: true,
  5675. checked: false,
  5676. }
  5677. }
  5678. toggle = () => {
  5679. this.setState({
  5680. disabled: !this.state.disabled,
  5681. })
  5682. }
  5683. sleep1s = () => {
  5684. return new Promise((resolve) => {
  5685. setTimeout(resolve, 1000)
  5686. })
  5687. }
  5688. onChangeAsync = async (val: boolean) => {
  5689. await this.sleep1s()
  5690. this.setState({
  5691. checked: val,
  5692. })
  5693. }
  5694. render() {
  5695. return (
  5696. <ScrollView>
  5697. <List renderHeader="基本">
  5698. <List.Item extra={<Switch />}>最简单的用法</List.Item>
  5699. </List>
  5700. <List renderHeader="不可用">
  5701. <List.Item extra={<Switch disabled={this.state.disabled} />}>
  5702. Switch 失效状态
  5703. </List.Item>
  5704. <WhiteSpace />
  5705. <WingBlank>
  5706. <Button type="primary" onPress={this.toggle}>
  5707. Toggle disabled
  5708. </Button>
  5709. </WingBlank>
  5710. </List>
  5711. <List renderHeader="文字和图标">
  5712. <List.Item
  5713. extra={
  5714. <Switch
  5715. checkedChildren="开"
  5716. unCheckedChildren="关"
  5717. defaultChecked
  5718. />
  5719. }
  5720. />
  5721. <List.Item
  5722. extra={<Switch checkedChildren="1" unCheckedChildren="0" />}
  5723. />
  5724. <List.Item
  5725. extra={
  5726. <Switch
  5727. checkedChildren={<Icon name="check" color="white" />}
  5728. unCheckedChildren={<Icon name="close" color="white" />}
  5729. defaultChecked
  5730. />
  5731. }
  5732. />
  5733. </List>
  5734. <List renderHeader="加载中">
  5735. <List.Item extra={<Switch checked loading />}>
  5736. 标识开关操作仍在执行中
  5737. </List.Item>
  5738. <List.Item extra={<Switch loading />} />
  5739. </List>
  5740. <List renderHeader="颜色">
  5741. <List.Item extra={<Switch checked color="red" />}>
  5742. color="red"
  5743. </List.Item>
  5744. </List>
  5745. <List renderHeader="异步">
  5746. <List.Item
  5747. extra={
  5748. <Switch
  5749. checked={this.state.checked}
  5750. onChange={this.onChangeAsync}
  5751. />
  5752. }>
  5753. onChange 返回 Promise
  5754. </List.Item>
  5755. </List>
  5756. </ScrollView>
  5757. )
  5758. }
  5759. }
  5760. ```
  5761. ## API
  5762. Properties | Descrition | Type | Default
  5763. -----------|------------|------|--------
  5764. | checked | Whether is checked by default | Boolean | false |
  5765. | defaultChecked | Whether to open initially | Boolean | false |
  5766. | disabled | whether is disabled | Boolean | false |
  5767. | loading | Loading status | Boolean | false |
  5768. | onChange | The callback function when changing, when the Promise is returned, the loading status will be displayed automatically | `(val: boolean) => void \| Promise<void>` | - |
  5769. | color | Background color when the switch is turned on. | String | #4dd865 |
  5770. | checkedChildren | Selected content | ReactNode | - |
  5771. | unCheckedChildren | Non-selected content | ReactNode | - |
  5772. | styles | Semantic DOM style | [SwitchStyle](#switchstyle-interface) | - |
  5773. ### SwitchStyle interface
  5774. ```typescript
  5775. interface SwitchStyle {
  5776. switch: ViewStyle
  5777. switch_inner: ViewStyle
  5778. switch_handle: ViewStyle
  5779. switch_checked: ViewStyle
  5780. switch_unchecked: ViewStyle
  5781. switch_inner_checked: ViewStyle
  5782. switch_inner_unchecked: ViewStyle
  5783. switch_handle_checked: ViewStyle
  5784. switch_handle_unchecked: ViewStyle
  5785. switch_checked_disabled: ViewStyle
  5786. switch_unchecked_disabled: ViewStyle
  5787. switch_handle_disabled: ViewStyle
  5788. }
  5789. ```
  5790. ---
  5791. ## TabBar
  5792. Source: https://rn.mobile.ant.design/components/tab-bar.md
  5793. # TabBar
  5794. Located at the bottom of the APP, to facilitate users to quickly switch between different functional modules。
  5795. ### Rule
  5796. - Used as a class of APP classification, the number of tab between 3-5 is better。
  5797. - Even if a Tab is not available, do not disable or remove the Tab。
  5798. - Use Badge make a hint,stay can also know that there is content update。
  5799. ## Examples
  5800. ```tsx
  5801. import { Icon, SearchBar, TabBar } from '@ant-design/react-native'
  5802. import React from 'react'
  5803. import { Text, View } from 'react-native'
  5804. export default class BasicTabBarExample extends React.Component<any, any> {
  5805. constructor(props: any) {
  5806. super(props)
  5807. this.state = {
  5808. selectedTab: 'redTab',
  5809. }
  5810. }
  5811. renderContent(pageText: any) {
  5812. return (
  5813. <View style={{ flex: 1, alignItems: 'center', backgroundColor: 'white' }}>
  5814. <SearchBar placeholder="Search" showCancelButton />
  5815. <Text style={{ margin: 50 }}>{pageText}</Text>
  5816. </View>
  5817. )
  5818. }
  5819. onChangeTab(tabName: any) {
  5820. this.setState({
  5821. selectedTab: tabName,
  5822. })
  5823. }
  5824. render() {
  5825. return (
  5826. <TabBar
  5827. unselectedTintColor="#949494"
  5828. tintColor="#33A3F4"
  5829. barTintColor="#f5f5f5">
  5830. <TabBar.Item
  5831. title="Life"
  5832. icon={<Icon name="home" />}
  5833. selected={this.state.selectedTab === 'blueTab'}
  5834. onPress={() => this.onChangeTab('blueTab')}>
  5835. {this.renderContent('Life Tab')}
  5836. </TabBar.Item>
  5837. <TabBar.Item
  5838. icon={<Icon name="ordered-list" />}
  5839. title="Koubei"
  5840. badge={2}
  5841. selected={this.state.selectedTab === 'redTab'}
  5842. onPress={() => this.onChangeTab('redTab')}>
  5843. {this.renderContent('Koubei Tab')}
  5844. </TabBar.Item>
  5845. <TabBar.Item
  5846. icon={<Icon name="like" />}
  5847. title="Friend"
  5848. selected={this.state.selectedTab === 'greenTab'}
  5849. onPress={() => this.onChangeTab('greenTab')}>
  5850. {this.renderContent('Friend Tab')}
  5851. </TabBar.Item>
  5852. <TabBar.Item
  5853. icon={<Icon name="user" />}
  5854. title="My"
  5855. selected={this.state.selectedTab === 'yellowTab'}
  5856. onPress={() => this.onChangeTab('yellowTab')}>
  5857. {this.renderContent('My Tab')}
  5858. </TabBar.Item>
  5859. </TabBar>
  5860. )
  5861. }
  5862. }
  5863. ```
  5864. ## API
  5865. ### TabBar
  5866. Properties | Descrition | Type | Default
  5867. -----------|------------|------|--------
  5868. | barTintColor | tabbar's background color | String | `white` |
  5869. | tintColor | selected's font color | String | `#108ee9` |
  5870. | unselectedTintColor | unselected's font color | String | '#888' |
  5871. | hidden | whether it is hidden | Boolean | false |
  5872. ### TabBar.Item
  5873. Properties | Descrition | Type | Default
  5874. -----------|------------|------|--------
  5875. | badge | badge number | Number \ String | 无 |
  5876. | onPress | on press the bar, need change component by yourself. state & selecte={true} | Function | `(){}` |
  5877. | selected | whether it is selected | Boolean | false |
  5878. | icon | the default icon | `Image Source | React.ReactNode` | |
  5879. | selectedIcon | the icon of selected | `Image Source | React.ReactNode` | |
  5880. | title | title | String | |
  5881. | key | unique identification | String | 无 |
  5882. | iconStyle | icon style | String | { width: 28, height: 28 } |
  5883. ---
  5884. ## Tabs
  5885. Source: https://rn.mobile.ant.design/components/tabs.md
  5886. # Tabs
  5887. A `Tabs` is used to allow users to switch between different views.
  5888. ### Rule
  5889. - Generally a `Tabs` should have 2-4 tab pane, the title of each tab pane should be concise,normally has 2-4 words..
  5890. - In the secondary page of iOS, it is not recommended to use left and right swipe to switch tab, which conflicts with back swipe gestrue in iOS. eg: tabs in details page.
  5891. ## Examples
  5892. ```tsx
  5893. import React from 'react'
  5894. import { ScrollView, Text, TouchableOpacity, View } from 'react-native'
  5895. import Tabs from '..'
  5896. const renderContent = (tab: any, index: any) => {
  5897. const style = {
  5898. paddingVertical: 40,
  5899. justifyContent: 'center',
  5900. alignItems: 'center',
  5901. margin: 10,
  5902. backgroundColor: '#ddd',
  5903. } as any
  5904. const content = [1, 2, 3, 4, 5, 6, 7, 8].map((i) => {
  5905. return (
  5906. <View key={`${index}_${i}`} style={style}>
  5907. <Text>
  5908. {tab.title} - {i}
  5909. </Text>
  5910. </View>
  5911. )
  5912. })
  5913. return (
  5914. <ScrollView key={index} style={{ backgroundColor: '#fff' }}>
  5915. {content}
  5916. </ScrollView>
  5917. )
  5918. }
  5919. export default class BasicTabsExample extends React.Component<any, any> {
  5920. render() {
  5921. const tabs = [
  5922. { title: 'First Tab' },
  5923. { title: 'Second Tab' },
  5924. { title: 'Third Tab' },
  5925. ]
  5926. const tabs2 = [
  5927. { title: '1st Tab' },
  5928. { title: '2nd Tab' },
  5929. { title: '3rd Tab' },
  5930. { title: '4th Tab' },
  5931. { title: '5th Tab' },
  5932. { title: '6th Tab' },
  5933. { title: '7th Tab' },
  5934. { title: '8th Tab' },
  5935. { title: '9th Tab' },
  5936. ]
  5937. const style = {
  5938. alignItems: 'center',
  5939. justifyContent: 'center',
  5940. height: 150,
  5941. backgroundColor: '#fff',
  5942. } as any
  5943. return (
  5944. <View style={{ flex: 1 }}>
  5945. <Tabs tabs={tabs}>
  5946. <View style={style}>
  5947. <Text>Content of First Tab</Text>
  5948. </View>
  5949. <View style={style}>
  5950. <Text>Content of Second Tab</Text>
  5951. </View>
  5952. <View style={style}>
  5953. <Text>Content of Third Tab</Text>
  5954. </View>
  5955. </Tabs>
  5956. <Text style={{ margin: 16 }}>Custom RenderTabBar</Text>
  5957. <Tabs
  5958. tabs={tabs}
  5959. renderTabBar={(tabProps) => (
  5960. <View
  5961. style={{
  5962. paddingHorizontal: 16,
  5963. flexDirection: 'row',
  5964. alignItems: 'center',
  5965. justifyContent: 'space-evenly',
  5966. }}>
  5967. {tabProps.tabs.map((tab, i) => (
  5968. // change the style to fit your needs
  5969. <TouchableOpacity
  5970. activeOpacity={0.9}
  5971. key={tab.key || i}
  5972. style={{
  5973. // width: '30%',
  5974. padding: 6,
  5975. }}
  5976. onPress={() => {
  5977. const { goToTab, onTabClick } = tabProps
  5978. // tslint:disable-next-line:no-unused-expression
  5979. onTabClick && onTabClick(tabs[i], i)
  5980. // tslint:disable-next-line:no-unused-expression
  5981. goToTab && goToTab(i)
  5982. }}>
  5983. <Text
  5984. style={{
  5985. color: tabProps.activeTab === i ? 'green' : '#333333',
  5986. }}>
  5987. {tab.title}
  5988. </Text>
  5989. </TouchableOpacity>
  5990. ))}
  5991. </View>
  5992. )}>
  5993. <View style={style}>
  5994. <Text>Content of First Tab</Text>
  5995. </View>
  5996. <View style={style}>
  5997. <Text>Content of Second Tab</Text>
  5998. </View>
  5999. <View style={style}>
  6000. <Text>Content of Third Tab</Text>
  6001. </View>
  6002. </Tabs>
  6003. <View style={{ flex: 2 }}>
  6004. <Tabs tabs={tabs2} initialPage={1} tabBarPosition="top">
  6005. {tabs2.map((tab, index) => renderContent(tab, index))}
  6006. </Tabs>
  6007. </View>
  6008. </View>
  6009. )
  6010. }
  6011. }
  6012. export const title = 'Tabs'
  6013. export const description = 'Tabs example'
  6014. ```
  6015. ## API
  6016. ### Tabs
  6017. Properties | Descrition | Type | Default | Required
  6018. -----------|------------|------|--------|--------
  6019. tabs | tabs data | Models.TabData[] | | true
  6020. tabBarPosition | TabBar's position | 'top' \| 'bottom' | top | false
  6021. renderTabBar | replace the TabBar | ((props: TabBarPropsType) => React.ReactNode) \| false | | false
  6022. initialPage | the tab when inital, index or key | number \| string | | false
  6023. page | current tab, index or key | number \| string | | false
  6024. swipeable | Whether to switch tabs with swipe gestrue in the content | boolean | true | false
  6025. useOnPan | use hand scroll | boolean | true | false
  6026. prerenderingSiblingsNumber | pre-render nearby # sibling, Infinity: render all the siblings, 0: render current page. | number | 1 | false
  6027. animated | Whether to change tabs with animation | boolean | true | false
  6028. onChange | Callback when tab is switched | (tab: Models.TabData, index: number) => void | | false
  6029. onTabClick | on tab click | (tab: Models.TabData, index: number) => void | | false
  6030. destroyInactiveTab | destroy inactive tab | boolean | false | false
  6031. distanceToChangeTab | distance to change tab, width ratio | number | 0.3 | false
  6032. usePaged | use paged | boolean | true | false
  6033. tabBarUnderlineStyle | style of the default tab bar's underline | React.CSSProperties \| any | | false
  6034. tabBarBackgroundColor | color of the default tab bar's background | string | | false
  6035. tabBarActiveTextColor | color of the default tab bar's text when active | string | | false
  6036. tabBarInactiveTextColor | color of the default tab bar's text when inactive | string | | false
  6037. tabBarTextStyle | tional styles to the tab bar's text | React.CSSProperties \| any | | false
  6038. renderTab | render for replace the tab of tabbar | (tab: Models.TabData) => React.ReactNode | | false
  6039. renderUnderline | renderUnderline | (style: any) => React.ReactNode | | false
  6040. ### Tabs.DefaultTabBar
  6041. Properties | Descrition | Type | Default | Required
  6042. -----------|------------|------|--------|--------
  6043. goToTab | call this function to switch Tab | (index: number) => boolean | | true
  6044. tabs | tabs data | Models.TabData[] | | true
  6045. activeTab | current tab | number | | true
  6046. animated | Whether to change tabs with animation | boolean | | true
  6047. renderTab | render for replace the tab of tabbar | (tab: Models.TabData) => React.ReactNode | | false
  6048. page | the size for the tab of tabbar | number | 5 | false
  6049. onTabClick | on tab click | (tab: Models.TabData, index: number) => void | | false
  6050. ---
  6051. ## Tag
  6052. Source: https://rn.mobile.ant.design/components/tag.md
  6053. # Tag
  6054. Tag for categorizing or markuping, can be used to make classification or mark the attributes and dimensions of objects.
  6055. ### Rules
  6056. - The content should be displayed completely.
  6057. ## Examples
  6058. ```tsx
  6059. import { Tag, WhiteSpace } from '@ant-design/react-native'
  6060. import React from 'react'
  6061. import { View } from 'react-native'
  6062. function onChange(selected: any) {
  6063. console.log(`tag selected: ${selected}`)
  6064. }
  6065. export default class BasicTagExample extends React.Component<any, any> {
  6066. render() {
  6067. return (
  6068. <View style={{ padding: 10 }}>
  6069. <Tag>Basic</Tag>
  6070. <WhiteSpace />
  6071. <Tag selected>Selected</Tag>
  6072. <WhiteSpace />
  6073. <Tag disabled>Disabled</Tag>
  6074. <WhiteSpace />
  6075. <Tag onChange={onChange}>Callback</Tag>
  6076. <WhiteSpace />
  6077. <Tag
  6078. closable
  6079. onClose={() => {
  6080. console.log('onClose')
  6081. }}
  6082. afterClose={() => {
  6083. console.log('afterClose')
  6084. }}>
  6085. Closable
  6086. </Tag>
  6087. <WhiteSpace />
  6088. <Tag small>Small and Readonly</Tag>
  6089. <WhiteSpace />
  6090. <Tag
  6091. onLongPress={() => {
  6092. console.log('onLongPress')
  6093. }}>
  6094. LongPress
  6095. </Tag>
  6096. </View>
  6097. )
  6098. }
  6099. }
  6100. ```
  6101. ## API
  6102. Properties | Descrition | Type | Default
  6103. -----------|------------|------|--------
  6104. | small | Whether to show a smaller size | Boolean | `false` |
  6105. | disabled | Whether is disabled | Boolean | `false` |
  6106. | closable | Whether can be closed(invalid in `small` or `disabled` mode) | Boolean | `false` |
  6107. | selected | Whether is selected by default | Boolean | `false` |
  6108. | onChange | The callback function that is triggered when the selected state changes. | (selected: bool): void | - |
  6109. | onClose | The callback function that is triggered when the tag is closed. | (): void | - |
  6110. | afterClose | The callback function that is triggered after close. | (): void | - |
  6111. | onLongPress | The callback function that is triggered when the tag is long pressed. | (): void | - |
  6112. ---
  6113. ## TextareaItem
  6114. Source: https://rn.mobile.ant.design/components/textarea-item.md
  6115. # TextareaItem
  6116. > This package has been deprecated in `5.2.1`, recommend [components/Input.TextArea](/components/input#inputtextarea)
  6117. A foundational component for inputting multi-line text into the app via a keyboard.
  6118. ### Rule
  6119. - Support text input via keyboard or clipboard.
  6120. - The cursor can be moved horizontally.
  6121. ## Examples
  6122. ```tsx
  6123. import { List, TextareaItem, Toast } from '@ant-design/react-native'
  6124. import React from 'react'
  6125. import { ScrollView } from 'react-native'
  6126. export default class BasicTextAreaItemExample extends React.Component<
  6127. any,
  6128. any
  6129. > {
  6130. constructor(props: any) {
  6131. super(props)
  6132. this.state = {
  6133. val: '默认带value',
  6134. }
  6135. }
  6136. onChange = (val: any) => {
  6137. // console.log(val);
  6138. this.setState({ val })
  6139. }
  6140. render() {
  6141. return (
  6142. <ScrollView
  6143. style={{ flex: 1 }}
  6144. automaticallyAdjustContentInsets={false}
  6145. showsHorizontalScrollIndicator={false}
  6146. showsVerticalScrollIndicator={false}>
  6147. <List renderHeader={'基本'}>
  6148. <TextareaItem rows={4} placeholder="固定行数" />
  6149. <TextareaItem rows={4} placeholder="多行带计数" count={100} />
  6150. <TextareaItem
  6151. rows={4}
  6152. placeholder="高度自适应"
  6153. autoHeight
  6154. style={{ paddingVertical: 5 }}
  6155. />
  6156. <TextareaItem value={this.state.val} onChange={this.onChange} />
  6157. <TextareaItem value="不可编辑 editable = {false}" editable={false} />
  6158. <TextareaItem clear={false} placeholder="不显示清除按钮" />
  6159. <TextareaItem
  6160. error
  6161. defaultValue="报错样式 error={true}"
  6162. onErrorClick={() => Toast.fail('Error message')}
  6163. />
  6164. </List>
  6165. </ScrollView>
  6166. )
  6167. }
  6168. }
  6169. ```
  6170. ## API
  6171. Properties | Descrition | Type | Default
  6172. -----------|------------|------|--------
  6173. | value | the value to show for the textarea (see [react doc](https://facebook.github.io/react/docs/forms.html) for more information about controlled component) | String | |
  6174. | defaultValue | provides an initial value that will change when the user starts typing. | String | - |
  6175. | placeholder | the string that will be rendered before text input has been entered. | String | '' |
  6176. | editable | whether is editable | bool | true |
  6177. | disabled | whether is disabled | bool | false |
  6178. | clear | whether to display the clear icon (it takes effect only if `editable` is `true` and `disabled` is `false`) | bool | false |
  6179. | rows | sets the number of lines for a textarea | number | 1 |
  6180. | count | it is used for word count and maxlength, the default is 0 which indicates that word count is turned off. | number | - |
  6181. | onChange | callback that is called when the textarea's text changes. | (val: string): void | - |
  6182. | error | whether to display error | bool | false |
  6183. | onErrorClick | callback that is called when the error icon is clicked | (): void | |
  6184. | autoHeight | auto adjust height (only use one of `autoHeight` and `rows` properties) | bool | false |
  6185. | labelNumber | number of label text, valid value is 2 to 7 | number | `5` |
  6186. | last | If it is the last item, the `borderBottom` will be removed, the default has `borderBottom` | bool | false |
  6187. > More available react-native `TextareaItem` API can be found at [react-native TextInput](http://facebook.github.io/react-native/docs/textinput.html)
  6188. ---
  6189. ## Toast
  6190. Source: https://rn.mobile.ant.design/components/toast.md
  6191. # Toast
  6192. A lightweight feedback or tips, used to display content that does not interrupt user operations. Suitable for page transitions, data interaction and other scenes.
  6193. ### Rules
  6194. - Toast with Icon, 4-6 words is recommended; Toast without Icon, the number of words should not exceed 14.
  6195. ## Examples
  6196. ```tsx
  6197. import { Button, List, Provider, Switch, Toast } from '@ant-design/react-native'
  6198. import React, { useEffect, useRef, useState } from 'react'
  6199. import { ActivityIndicator, ScrollView, Text } from 'react-native'
  6200. const ToastExample = () => {
  6201. const handler = useRef<number>()
  6202. const [enableMask, setEnableMask] = useState(Toast.getConfig().mask)
  6203. const [enableStack, setEnableStack] = useState(Toast.getConfig().stackable)
  6204. return (
  6205. <Provider>
  6206. <ScrollView>
  6207. <List>
  6208. <List.Item
  6209. extra={
  6210. <Switch
  6211. checked={enableMask}
  6212. onChange={(mask) => {
  6213. Toast.config({ mask })
  6214. setEnableMask(Toast.getConfig().mask)
  6215. }}
  6216. />
  6217. }>
  6218. Enable mask
  6219. <List.Item.Brief>是否显示透明蒙层,防止触摸穿透</List.Item.Brief>
  6220. </List.Item>
  6221. <List.Item
  6222. extra={
  6223. <Switch
  6224. checked={enableStack}
  6225. onChange={(stackable) => {
  6226. Toast.config({ stackable })
  6227. setEnableStack(Toast.getConfig().stackable)
  6228. }}
  6229. />
  6230. }>
  6231. Enable stackable
  6232. <List.Item.Brief>是否允许叠加显示</List.Item.Brief>
  6233. </List.Item>
  6234. </List>
  6235. <List renderHeader="图标">
  6236. <Button
  6237. onPress={() => {
  6238. Toast.success('Success')
  6239. }}>
  6240. 成功
  6241. </Button>
  6242. <Button
  6243. onPress={() => {
  6244. Toast.fail('Fail')
  6245. }}>
  6246. 失败
  6247. </Button>
  6248. <Button
  6249. onPress={() => {
  6250. Toast.offline('Network connection failed !!!')
  6251. }}>
  6252. 网络失败
  6253. </Button>
  6254. <Button
  6255. onPress={() => {
  6256. Toast.loading('loading...')
  6257. }}>
  6258. 加载中
  6259. </Button>
  6260. <Button
  6261. onPress={() => {
  6262. Toast.show({
  6263. content: '上传中',
  6264. icon: <ActivityIndicator />,
  6265. })
  6266. }}>
  6267. 自定义图标
  6268. </Button>
  6269. </List>
  6270. <List renderHeader="更多功能">
  6271. <Button
  6272. onPress={() => {
  6273. Toast.show({
  6274. content: 'Hello World',
  6275. position: 'top',
  6276. })
  6277. }}>
  6278. 顶部提示
  6279. </Button>
  6280. <Button
  6281. onPress={() => {
  6282. Toast.show({
  6283. content: 'Hello World',
  6284. position: 'bottom',
  6285. })
  6286. }}>
  6287. 底部提示
  6288. </Button>
  6289. <Button
  6290. onPress={() => {
  6291. Toast.show({
  6292. icon: 'loading',
  6293. content: <CountDownText />,
  6294. duration: 5,
  6295. })
  6296. }}>
  6297. 动态内容
  6298. </Button>
  6299. </List>
  6300. <List renderHeader="手动清除">
  6301. <Button
  6302. onPress={() => {
  6303. handler.current = Toast.show({
  6304. content: '这条提示不会自动消失',
  6305. duration: 0,
  6306. position: 'top',
  6307. mask: false,
  6308. })
  6309. }}>
  6310. 显示
  6311. </Button>
  6312. <Button
  6313. onPress={() => {
  6314. handler.current && Toast.remove(handler.current)
  6315. }}>
  6316. 清除
  6317. </Button>
  6318. <Button
  6319. onPress={() => {
  6320. Toast.removeAll()
  6321. }}>
  6322. 关闭所有
  6323. </Button>
  6324. </List>
  6325. </ScrollView>
  6326. </Provider>
  6327. )
  6328. }
  6329. export default ToastExample
  6330. const CountDownText = () => {
  6331. const [count, setCount] = useState(5)
  6332. const interval = useRef<any>()
  6333. useEffect(() => {
  6334. interval.current = setInterval(() => {
  6335. setCount((x) => {
  6336. if (x > 1) {
  6337. return x - 1
  6338. } else {
  6339. return x
  6340. }
  6341. })
  6342. }, 1000)
  6343. return () => {
  6344. interval.current && clearInterval(interval.current)
  6345. }
  6346. }, [])
  6347. return <Text style={{ color: '#ffffff' }}>还剩 {count} 秒</Text>
  6348. }
  6349. ```
  6350. ## API
  6351. `Toast` only supports Imperative calls. The argument type is `string | ToastProps`.
  6352. - `Toast.show(props)` - New in `5.2.1`
  6353. - `Toast.success(props)`
  6354. - `Toast.fail(props)`
  6355. - `Toast.info(props)`
  6356. - `Toast.loading(props)`
  6357. - `Toast.offline(props)`
  6358. `Toast.show(string)`'s default config is `{duration:1.5, mask: false}`. Another method is to specify a shortcut to the `icon`.
  6359. ToastProps has these fields:
  6360. | Properties | Descrition | Type | Required | Default | Version |
  6361. | ---------- | ---------- | -----| -----------| --------|---------|
  6362. | content | Toast content | `String | React.ReactNode` | Yes | - | |
  6363. | duration | Delay time to close, which units is second | number | No | 3 | |
  6364. | icon | Toast icon | `'success' | 'fail' | 'offline' | 'loading' | React.ReactNode` | No | - | `5.2.1` |
  6365. | mask | Whether to show a transparent mask, which will prevent touch event of the whole page | Boolean | No | true | |
  6366. | onClose | A callback function Triggered when the Toast is closed | Function | No | - | |
  6367. | position | Vertical display position | `'top' | 'bottom' | 'center'` | No | `'center'` | `5.2.1` |
  6368. | stackable | Whether to allow toast overlay | Boolean | No | true | |
  6369. | styles | Semantic DOM style | [ToastStyle](#toaststyle-interface) | No | - | `5.2.1` |
  6370. > **Notice:** OnClose is invalid and Toast does not hide, If set duration = 0, toast will not auto hide, you have to manually do it.
  6371. ```js
  6372. import { Toast } from '@ant-design/react-native';
  6373. const key = Toast.loading('message');
  6374. Toast.remove(key);
  6375. ```
  6376. ### Toast.removeAll
  6377. Turn off `Toast` in all displays.
  6378. ```ts
  6379. Toast.removeAll()
  6380. ```
  6381. ### Toast.config
  6382. Methods for global configuration. Support `duration`、`mask`、`onClose`、`position`、`stackable` and `style`. The configuration method is as follows:
  6383. ```ts
  6384. Toast.config({ duration: 1, position: 'top' })
  6385. // get current config
  6386. Toast.getConfig()
  6387. ```
  6388. ### Toast.useToast()
  6389. New in `5.3.0`. antd-mobile-rn will inserted into the root node of `<Provider>` through `Portal.add` when call toast methods. Whose context is different with origin code located context.
  6390. <br/>
  6391. When you need context info (like **Modal** context), you can use `toast.useToast` to get `toastApi` instance and `contextHolder` node. And put it in your children:
  6392. ```jsx
  6393. import { Modal } from 'react-native'
  6394. import { Toast } from '@ant-design/react-native'
  6395. const [toastApi, contextHolder] = Toast.useToast();
  6396. const showLoading = () => {
  6397. toastApi.loading(
  6398. // ...
  6399. );
  6400. }
  6401. return (
  6402. <Modal>
  6403. {contextHolder}
  6404. <View>
  6405. ...
  6406. </View>
  6407. </Modal>
  6408. );
  6409. ```
  6410. ### InputStyle interface
  6411. ```typescript
  6412. interface ToastStyle {
  6413. container: ViewStyle
  6414. innerContainer: ViewStyle
  6415. innerWrap: ViewStyle
  6416. iconToast: ViewStyle
  6417. textToast: ViewStyle
  6418. content: TextStyle
  6419. image: TextStyle
  6420. centering: ViewStyle
  6421. }
  6422. ```
  6423. ---
  6424. ## Tooltip
  6425. Source: https://rn.mobile.ant.design/components/tooltip.md
  6426. # Tooltip
  6427. After clicking on a control or an area, a Tooltip menu appears for doing more.
  6428. If set mask prop, it is recommended to exit by clicking on any of the mask layers.
  6429. ## Examples
  6430. ```tsx
  6431. import {
  6432. Button,
  6433. Icon,
  6434. List,
  6435. Provider,
  6436. Toast,
  6437. Tooltip,
  6438. } from '@ant-design/react-native'
  6439. import React, { useEffect, useState } from 'react'
  6440. import { ScrollView, Text, View } from 'react-native'
  6441. import { Action, TooltipProps } from '../PropsType'
  6442. const actions: Action[] = [
  6443. { key: 'scan', icon: <Icon name="scan" />, text: '扫一扫' },
  6444. { key: 'payment', icon: <Icon name="pay-circle" />, text: '付钱/收钱' },
  6445. { key: 'bus', icon: <Icon name="qrcode" />, text: '乘车码' },
  6446. { key: 'assistant', icon: <Icon name="ant-design" />, text: '智能助理' },
  6447. ]
  6448. export default function TooltipExample() {
  6449. const [placement, setPlacement] =
  6450. useState<TooltipProps['placement']>('top-start')
  6451. useEffect(() => {
  6452. let current = 0
  6453. const timer = setInterval(() => {
  6454. if (current >= directionList.length - 1) {
  6455. current = 0
  6456. } else {
  6457. current += 1
  6458. }
  6459. setPlacement(directionList[current])
  6460. }, 2000)
  6461. return () => {
  6462. clearInterval(timer)
  6463. }
  6464. }, [])
  6465. return (
  6466. <Provider>
  6467. <ScrollView {...Tooltip.scrollProps}>
  6468. <List renderHeader="基本用法">
  6469. <Tooltip
  6470. content="Hello World"
  6471. trigger="onPress"
  6472. placement="right"
  6473. defaultVisible>
  6474. <Button style={{ alignSelf: 'flex-start', margin: 10 }}>
  6475. 点我
  6476. </Button>
  6477. </Tooltip>
  6478. </List>
  6479. <List renderHeader="深色气泡">
  6480. <Tooltip content="Hello World" placement="bottom" mode="dark" visible>
  6481. <Button
  6482. style={{ alignSelf: 'flex-start', margin: 10, marginBottom: 30 }}>
  6483. 点我
  6484. </Button>
  6485. </Tooltip>
  6486. </List>
  6487. <List renderHeader="气泡位置">
  6488. <Tooltip
  6489. visible
  6490. content={
  6491. <View>
  6492. <Text>Popover</Text>
  6493. <Text>Content</Text>
  6494. </View>
  6495. }
  6496. styles={{ arrow: { borderTopColor: 'yellow' } }}
  6497. placement={placement}>
  6498. <Button style={{ alignSelf: 'center', margin: 10 }}>
  6499. {placement}
  6500. </Button>
  6501. </Tooltip>
  6502. </List>
  6503. <List renderHeader="浅色气泡菜单">
  6504. <Tooltip.Menu
  6505. actions={actions}
  6506. placement="bottom-start"
  6507. onAction={(node) => Toast.show(`选择了 ${node.text}`)}
  6508. trigger="onPress">
  6509. <Button style={{ alignSelf: 'flex-start', margin: 10 }}>
  6510. 点我
  6511. </Button>
  6512. </Tooltip.Menu>
  6513. </List>
  6514. <List renderHeader="深色气泡菜单">
  6515. <Tooltip.Menu
  6516. mode="dark"
  6517. actions={actions}
  6518. placement="bottom-start"
  6519. onAction={(node) => Toast.show(`选择了 ${node.text}`)}
  6520. trigger="onPress">
  6521. <Button style={{ alignSelf: 'flex-start', margin: 10 }}>
  6522. 点我
  6523. </Button>
  6524. </Tooltip.Menu>
  6525. </List>
  6526. <List renderHeader="超过最大数量,隐藏滚动">
  6527. <Tooltip.Menu
  6528. actions={actions}
  6529. maxCount={2}
  6530. onAction={(node) => Toast.show(`选择了 ${node.text}`)}
  6531. placement="bottom-start"
  6532. trigger="onPress">
  6533. <Button style={{ alignSelf: 'flex-start', margin: 10 }}>
  6534. 点我
  6535. </Button>
  6536. </Tooltip.Menu>
  6537. </List>
  6538. </ScrollView>
  6539. </Provider>
  6540. )
  6541. }
  6542. const directionList = [
  6543. 'top-start',
  6544. 'top',
  6545. 'top-end',
  6546. 'right-start',
  6547. 'right',
  6548. 'right-end',
  6549. 'bottom-end',
  6550. 'bottom',
  6551. 'bottom-start',
  6552. 'left-end',
  6553. 'left',
  6554. 'left-start',
  6555. ] as const
  6556. ```
  6557. ## API
  6558. ### Tooltip
  6559. | Name | Description | Type | Default |
  6560. | --- | --- | --- | --- |
  6561. | children | The element that triggered the Tooltip | `React.ReactElement` | - |
  6562. | content | The content of the Tooltip | `React.ReactNode` | - |
  6563. | defaultVisible | Whether to show or hide by default | `boolean` | `false` |
  6564. | mode | Set bright color mode or black mode | `'light' | 'dark'` | `'light'` |
  6565. | crossOffset | Set the offset of the pop-up window position; Top: Additional offset applied along the main axis between the element and its triggering element. Left: Additional offset applied along the horizontal axis between the element and its triggering element. | `{ top: number, left: number }` | `'{ top: StatusBar.currentHeight, left: 0 } '` |
  6566. | onVisibleChange | Callback when the visible prop is changed | `(visible: boolean) => void` | - |
  6567. | placement | The position of the Tooltip | `'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end'` | `'top'` |
  6568. | styles | Semantic DOM style | [TooltipStyle](#tooltipstyle-interface) | - |
  6569. | trigger | Event to trigger | `'onPress'` | - |
  6570. | visible | Whether to display pop-up content in controlled mode | `boolean` | - |
  6571. ### Ref
  6572. | Name | Description | Type |
  6573. | ------- | -------------------------------- | ------------ |
  6574. | hide | Hide the Tooltip | `() => void` |
  6575. | show | Show the Tooltip | `() => void` |
  6576. | visible | Whether the Tooltip is diplaying | `boolean` |
  6577. ## Tooltip.scrollProps
  6578. While `Tooltip` is inside a `<ScrollView />`, please pread `Tooltip.scrollProps` to the ScrollView,
  6579. <br/>
  6580. otherwise it will not follow the scroll
  6581. ```jsx
  6582. import { ScrollView } from 'react-native'
  6583. import { Tooltip } from '@ant-design/react-native'
  6584. <ScrollView {...Tooltip.scrollProps}>
  6585. <Tooltip>...</Tooltip>
  6586. <ScrollView>
  6587. ```
  6588. ## Tooltip.Menu
  6589. ### Props
  6590. Except for `content`, all other attributes are inherited from `Tooltip`, the unique attributes are as follows:
  6591. | Name | Description | Type | Default |
  6592. | --- | --- | --- | --- |
  6593. | actions | Menu list, used when the pop-up content is a standard menu | `Action[]` | - |
  6594. | maxCount | Maximum number of menu lists, if exceeded, hide for scrolling | `number` | - |
  6595. | onAction | Callback of the selected menum, when the menu list is used | `(item: Action) => void` | - |
  6596. ### Action
  6597. | Name | Description | Type | Default |
  6598. | --- | --- | --- | --- |
  6599. | disabled | Whether disabled | `boolean` | `false` |
  6600. | icon | The icon of the menu item | `ReactNode` | `null` |
  6601. | key | The unique identifier of the menu, the default is `index` | `string | number` | `actions` array's `index` |
  6602. | onPress | Triggered on click | `() => void` | - |
  6603. | text | Menu list, used when the pop-up content is a standard menu | `ReactNode` | - |
  6604. ### TooltipStyle interface
  6605. ```typescript
  6606. interface TooltipStyle extends ListItemStyle {
  6607. tooltip: ViewStyle
  6608. tooltipText: TextStyle
  6609. arrow: ViewStyle // `borderTopColor` sets the arrow bg color
  6610. }
  6611. ```
  6612. ### Ref
  6613. Same as Tooltip.
  6614. ## FAQ
  6615. ### Why can't some children components wrapped by Tooltip be opened onPress?
  6616. First, Tooltip's children must be `React.ReactElement`, which is a JSX Element rather than a variable.
  6617. ```jsx
  6618. const element = <Button>press</Button>
  6619. <Tooltip
  6620. content="Hello World"
  6621. defaultVisible>
  6622. {element} // ❌ DO NOT USE
  6623. <Button>press</Button> // ✅ YES
  6624. </Tooltip>
  6625. ```
  6626. Secondly, the positioning of Tooltip is calculated based on `View.onLayout`, so the children component must support the [onLayout](https://reactnative.dev/docs/view#onlayout) event.
  6627. ```jsx
  6628. const CustomButton = (props: {
  6629. onLayout: (event: LayoutChangeEvent) => void
  6630. }) => (
  6631. <View onLayout={props.onLayout}>
  6632. ...
  6633. </View>
  6634. )
  6635. <Tooltip
  6636. content="Hello World"
  6637. defaultVisible>
  6638. <CustomButton>press<CustomButton>
  6639. </Tooltip>
  6640. ```
  6641. ---
  6642. ## View
  6643. Source: https://rn.mobile.ant.design/components/view.md
  6644. # View
  6645. Safe View
  6646. ### Rules
  6647. - Support `string`/`number` ReactNode
  6648. ## Examples
  6649. ```tsx
  6650. import { View } from '@ant-design/react-native'
  6651. import React from 'react'
  6652. export default class SafeViewExample extends React.Component<any, any> {
  6653. render() {
  6654. return (
  6655. <View
  6656. style={{
  6657. flexDirection: 'row',
  6658. height: 100,
  6659. padding: 20,
  6660. }}>
  6661. <View style={{ backgroundColor: 'blue', flex: 0.3 }} />
  6662. <View style={{ backgroundColor: 'red', flex: 0.5 }} />
  6663. <View>Hello World!</View>
  6664. </View>
  6665. )
  6666. }
  6667. }
  6668. ```
  6669. ## API
  6670. Properties | Descrition | Type | Default
  6671. -----------|------------|------|--------
  6672. | children | child component | `React.ReactNode` \| `React.ReactText` | - |
  6673. | style | style | `StyleProp<ViewStyle>` \| `StyleProp<TextStyle>` | - |
  6674. > More available react-native `View` API can be found at [react-native View](http://facebook.github.io/react-native/docs/view.html)
  6675. ## FAQ
  6676. ### What difference between it and React Native's built-in components View and Text?
  6677. React Native's View does not support `children` of type `string` / `number`.
  6678. Misinformation will cause crash and no Code Line Numbers
  6679. **This component can be used to evacuate errors once, giving priority to ensuring that the device does not crash.**
  6680. Common mistakes:
  6681. ```jsx
  6682. const length = arr.length;
  6683. <View>
  6684. {length && <Component />}
  6685. </View>
  6686. // when length=0, actually render:
  6687. <View>
  6688. 0
  6689. </View>
  6690. ```
  6691. Attention, only one layer of protection can be achieved, even `<React.Fragment>` children maked worng type:
  6692. ```jsx
  6693. import {View} from '@ant-design/react-native'
  6694. <View>
  6695. {/* still crash */}
  6696. <React.Fragment>
  6697. 0
  6698. </React.Fragment>
  6699. {/* still crash */}
  6700. <>''</>
  6701. </View>
  6702. ```
  6703. ---
  6704. ## WhiteSpace
  6705. Source: https://rn.mobile.ant.design/components/white-space.md
  6706. # WhiteSpace
  6707. Layout controls
  6708. ## Examples
  6709. ```tsx
  6710. import { WhiteSpace } from '@ant-design/react-native'
  6711. import React from 'react'
  6712. import { Text, View } from 'react-native'
  6713. const PlaceHolder = (props: any) => (
  6714. <View
  6715. style={{
  6716. backgroundColor: '#fff',
  6717. height: 30,
  6718. alignItems: 'center',
  6719. justifyContent: 'center',
  6720. }}
  6721. {...props}>
  6722. <Text style={{ color: '#bbb' }}>Block</Text>
  6723. </View>
  6724. )
  6725. export default class WhiteSpaceExample extends React.Component<any, any> {
  6726. render() {
  6727. return (
  6728. <View>
  6729. <WhiteSpace size="xs" />
  6730. <PlaceHolder />
  6731. <WhiteSpace size="sm" />
  6732. <PlaceHolder />
  6733. <WhiteSpace />
  6734. <PlaceHolder />
  6735. <WhiteSpace size="lg" />
  6736. <PlaceHolder />
  6737. <WhiteSpace size="xl" />
  6738. <PlaceHolder />
  6739. </View>
  6740. )
  6741. }
  6742. }
  6743. ```
  6744. ## API
  6745. Properties | Descrition | Type | Default
  6746. -----------|------------|------|--------
  6747. | size | up and down margins, optional values:`xs`,`sm`,`md`,`lg`,`xl` | string | `md` |
  6748. ---
  6749. ## WingBlank
  6750. Source: https://rn.mobile.ant.design/components/wing-blank.md
  6751. # WingBlank
  6752. Layout controls
  6753. ## Examples
  6754. ```tsx
  6755. import { WhiteSpace, WingBlank } from '@ant-design/react-native'
  6756. import React from 'react'
  6757. import { Text, View } from 'react-native'
  6758. const PlaceHolder = (props: any) => (
  6759. <View
  6760. style={{
  6761. backgroundColor: '#fff',
  6762. height: 30,
  6763. alignItems: 'center',
  6764. justifyContent: 'center',
  6765. }}
  6766. {...props}>
  6767. <Text style={{ color: '#bbb' }}>Block</Text>
  6768. </View>
  6769. )
  6770. export default class WingBlankExample extends React.Component<any, any> {
  6771. render() {
  6772. return (
  6773. <View>
  6774. <WhiteSpace />
  6775. <WingBlank>
  6776. <PlaceHolder />
  6777. </WingBlank>
  6778. <WhiteSpace size="lg" />
  6779. <WingBlank size="md">
  6780. <PlaceHolder />
  6781. </WingBlank>
  6782. <WhiteSpace size="lg" />
  6783. <WingBlank size="sm">
  6784. <PlaceHolder />
  6785. </WingBlank>
  6786. </View>
  6787. )
  6788. }
  6789. }
  6790. ```
  6791. ## API
  6792. Properties | Descrition | Type | Default
  6793. -----------|------------|------|--------
  6794. | size | left and right blank space, optional values:`sm`,`md`,`lg` | string | `lg` |
  6795. ---