test.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import React from 'react';
  2. import { ScrollView, Text, View, TouchableOpacity } from 'react-native';
  3. import { Tabs } from '@ant-design/react-native';
  4. const renderContent = (tab, index) => {
  5. const style = {
  6. paddingVertical: 40,
  7. justifyContent: 'center',
  8. alignItems: 'center',
  9. margin: 10,
  10. backgroundColor: '#ddd',
  11. };
  12. const content = [1, 2, 3, 4, 5, 6, 7, 8].map(i => {
  13. return (
  14. <View key={`${index}_${i}`} style={style}>
  15. <Text>
  16. {tab.title} - {i}
  17. </Text>
  18. </View>
  19. );
  20. });
  21. return <ScrollView style={{ backgroundColor: '#fff' }}>{content}</ScrollView>;
  22. };
  23. export default class BasicTabsExample extends React.Component {
  24. render() {
  25. const tabs = [
  26. { title: 'First Tab' },
  27. { title: 'Second Tab' },
  28. { title: 'Third Tab' },
  29. ];
  30. const tabs2 = [
  31. { title: '1st Tab' },
  32. { title: '2nd Tab' },
  33. { title: '3rd Tab' },
  34. { title: '4th Tab' },
  35. { title: '5th Tab' },
  36. { title: '6th Tab' },
  37. { title: '7th Tab' },
  38. { title: '8th Tab' },
  39. { title: '9th Tab' },
  40. ];
  41. const style = {
  42. alignItems: 'center',
  43. justifyContent: 'center',
  44. height: 150,
  45. backgroundColor: '#fff',
  46. };
  47. return (
  48. <View style={{ flex: 1 }}>
  49. <Tabs tabs={tabs}>
  50. <View style={style}>
  51. <Text>Content of First Tab</Text>
  52. </View>
  53. <View style={style}>
  54. <Text>Content of Second Tab</Text>
  55. </View>
  56. <View style={style}>
  57. <Text>Content of Third Tab</Text>
  58. </View>
  59. </Tabs>
  60. <Text style={{ margin: 16 }}>Custom RenderTabBar</Text>
  61. <Tabs
  62. tabs={tabs}
  63. renderTabBar={tabProps => (
  64. <View
  65. style={{
  66. paddingHorizontal: 16,
  67. flexDirection: 'row',
  68. alignItems: 'center',
  69. justifyContent: 'space-evenly',
  70. }}
  71. >
  72. {tabProps.tabs.map((tab, i) => (
  73. // change the style to fit your needs
  74. <TouchableOpacity
  75. activeOpacity={0.9}
  76. key={tab.key || i}
  77. style={{
  78. // width: '30%',
  79. padding: 6,
  80. }}
  81. onPress={() => {
  82. const { goToTab, onTabClick } = tabProps;
  83. // tslint:disable-next-line:no-unused-expression
  84. onTabClick && onTabClick(tabs[i], i);
  85. // tslint:disable-next-line:no-unused-expression
  86. goToTab && goToTab(i);
  87. }}
  88. >
  89. <Text
  90. style={{
  91. color: tabProps.activeTab === i ? 'green' : undefined,
  92. }}
  93. >
  94. {tab.title}
  95. </Text>
  96. </TouchableOpacity>
  97. ))}
  98. </View>
  99. )}
  100. >
  101. <View style={style}>
  102. <Text>Content of First Tab</Text>
  103. </View>
  104. <View style={style}>
  105. <Text>Content of Second Tab</Text>
  106. </View>
  107. <View style={style}>
  108. <Text>Content of Third Tab</Text>
  109. </View>
  110. </Tabs>
  111. <View style={{ flex: 2 }}>
  112. <Tabs tabs={tabs2} initialPage={1} tabBarPosition="top">
  113. {renderContent}
  114. </Tabs>
  115. </View>
  116. </View>
  117. );
  118. }
  119. }
  120. export const title = 'Tabs';
  121. export const description = 'Tabs example';
  122. // fetch(uploadURL,{
  123. // method:'POST',
  124. // headers:{
  125. // 'Content-Type':'multipart/form-data',
  126. // },
  127. // body:formData,
  128. // })
  129. // .then((response) => response.text() )
  130. // .then((responseData)=>{
  131. //
  132. // console.log('responseData',responseData);
  133. // })
  134. // .catch((error)=>{console.error('error',error)});