App.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import React, {useState} from 'react';
  2. import {
  3. NativeModules,
  4. StyleSheet,
  5. View,
  6. StatusBar,
  7. Text,
  8. TouchableOpacity,
  9. ActionSheetIOS,
  10. Platform,
  11. Button,
  12. } from 'react-native';
  13. import Icon from 'react-native-vector-icons/Ionicons';
  14. const App = () => {
  15. const {CallNative} = NativeModules;
  16. if (Platform.OS === 'ios') {
  17. CallNative.connect();
  18. }
  19. Icon.loadFont();
  20. const IconButton = ({onPress, iconName, iconSize, iconColor}: any) => {
  21. return (
  22. <TouchableOpacity onPress={onPress}>
  23. <Icon
  24. name={iconName}
  25. size={iconSize}
  26. color={iconColor}
  27. style={styles.iconButton}
  28. />
  29. </TouchableOpacity>
  30. );
  31. };
  32. const [isActionSheetVisible, setActionSheetVisible] = useState(false);
  33. const handlePress = () => {
  34. showActionMenu();
  35. };
  36. const showActionMenu = () => {
  37. if (Platform.OS === 'ios') {
  38. const options = [
  39. 'Setting',
  40. 'Profile',
  41. 'Contact Center',
  42. 'Notification Center',
  43. 'Chat',
  44. 'Call',
  45. 'Live Streaming',
  46. 'Cancel',
  47. ];
  48. ActionSheetIOS.showActionSheetWithOptions(
  49. {
  50. options: options,
  51. cancelButtonIndex: options.length - 1,
  52. // destructiveButtonIndex: 2, // Index of the destructive option (optional)
  53. tintColor: 'blue', // Color of the option text (optional)
  54. },
  55. buttonIndex => {
  56. // Handle the selected option
  57. if (buttonIndex === 0) {
  58. CallNative.openSetting();
  59. }
  60. if (buttonIndex === 1) {
  61. CallNative.openProfile();
  62. }
  63. if (buttonIndex === 2) {
  64. CallNative.openContactCenter();
  65. }
  66. if (buttonIndex === 3) {
  67. CallNative.openNotificationCenter();
  68. }
  69. if (buttonIndex === 4) {
  70. CallNative.openChat();
  71. }
  72. if (buttonIndex === 5) {
  73. CallNative.openCall();
  74. }
  75. if (buttonIndex === 6) {
  76. CallNative.openStreaming();
  77. }
  78. else {
  79. // Cancel button or tapping outside the action menu
  80. }
  81. },
  82. );
  83. } else {
  84. // Android implementation
  85. setActionSheetVisible(true);
  86. }
  87. };
  88. const handleActionSheetPress = async (buttonIndex: any) => {
  89. setActionSheetVisible(false);
  90. if (buttonIndex === 0) {
  91. try {
  92. CallNative.openSetting();
  93. } catch (e) {
  94. console.log(e);
  95. }
  96. }
  97. if (buttonIndex === 1) {
  98. try {
  99. CallNative.openProfile();
  100. } catch (e) {
  101. console.log(e);
  102. }
  103. }
  104. if (buttonIndex === 2) {
  105. try {
  106. CallNative.openContactCenter();
  107. } catch (e) {
  108. console.log(e);
  109. }
  110. }
  111. if (buttonIndex === 3) {
  112. try {
  113. CallNative.openNotificationCenter();
  114. } catch (e) {
  115. console.log(e);
  116. }
  117. }
  118. if (buttonIndex === 4) {
  119. try {
  120. CallNative.openChat();
  121. } catch (e) {
  122. console.log(e);
  123. }
  124. }
  125. if (buttonIndex === 5) {
  126. try {
  127. CallNative.openCall();
  128. } catch (e) {
  129. console.log(e);
  130. }
  131. }
  132. if (buttonIndex === 6) {
  133. try {
  134. CallNative.openStreaming();
  135. } catch (e) {
  136. console.log(e);
  137. }
  138. }
  139. };
  140. return (
  141. <View style={styles.container}>
  142. <StatusBar animated={true} barStyle="default" showHideTransition="fade" />
  143. <View style={styles.viewAppBar}>
  144. <Text style={styles.textTitle}>NexilisSampleCode</Text>
  145. <IconButton
  146. onPress={handlePress}
  147. iconName="ellipsis-horizontal"
  148. iconSize={30}
  149. iconColor="white"
  150. />
  151. </View>
  152. {isActionSheetVisible && (
  153. <View>
  154. <Button
  155. title="Setting"
  156. onPress={() => handleActionSheetPress(0)}
  157. />
  158. <Button
  159. title="Profile"
  160. onPress={() => handleActionSheetPress(1)}
  161. />
  162. <Button
  163. title="Contact Center"
  164. onPress={() => handleActionSheetPress(2)}
  165. />
  166. <Button
  167. title="Notification Center"
  168. onPress={() => handleActionSheetPress(3)}
  169. />
  170. <Button
  171. title="Chat"
  172. onPress={() => handleActionSheetPress(4)}
  173. />
  174. <Button
  175. title="Call"
  176. onPress={() => handleActionSheetPress(5)}
  177. />
  178. <Button
  179. title="Live Streaming"
  180. onPress={() => handleActionSheetPress(6)}
  181. />
  182. <Button title="Cancel" onPress={() => setActionSheetVisible(false)} />
  183. </View>
  184. )}
  185. </View>
  186. );
  187. };
  188. const styles = StyleSheet.create({
  189. loginButtonSection: {
  190. width: '100%',
  191. height: '100%',
  192. justifyContent: 'center',
  193. alignItems: 'center',
  194. },
  195. container: {
  196. flex: 1,
  197. },
  198. viewAppBar: {
  199. width: '100%',
  200. height: '10%',
  201. backgroundColor: '#3669ad',
  202. justifyContent: 'center',
  203. position: 'relative',
  204. },
  205. textTitle: {
  206. position: 'absolute',
  207. left: '30%',
  208. color: 'white',
  209. fontSize: 18,
  210. top: '50%',
  211. },
  212. iconButton: {
  213. position: 'absolute',
  214. right: '5%',
  215. top: -8,
  216. color: 'white',
  217. },
  218. });
  219. export default App;