@rematter/pylon-react-native 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +503 -0
  2. package/RNPylonChat.podspec +33 -0
  3. package/android/build.gradle +74 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/java/com/pylon/chatwidget/Pylon.kt +149 -0
  7. package/android/src/main/java/com/pylon/chatwidget/PylonChat.kt +715 -0
  8. package/android/src/main/java/com/pylon/chatwidget/PylonChatController.kt +63 -0
  9. package/android/src/main/java/com/pylon/chatwidget/PylonChatListener.kt +76 -0
  10. package/android/src/main/java/com/pylon/chatwidget/PylonChatView.kt +7 -0
  11. package/android/src/main/java/com/pylon/chatwidget/PylonConfig.kt +62 -0
  12. package/android/src/main/java/com/pylon/chatwidget/PylonDebugView.kt +76 -0
  13. package/android/src/main/java/com/pylon/chatwidget/PylonUser.kt +41 -0
  14. package/android/src/main/java/com/pylonchat/reactnative/RNPylonChatPackage.kt +17 -0
  15. package/android/src/main/java/com/pylonchat/reactnative/RNPylonChatView.kt +298 -0
  16. package/android/src/main/java/com/pylonchat/reactnative/RNPylonChatViewManager.kt +201 -0
  17. package/ios/PylonChat/PylonChat.swift +865 -0
  18. package/ios/RNPylonChatView.swift +332 -0
  19. package/ios/RNPylonChatViewManager.m +55 -0
  20. package/ios/RNPylonChatViewManager.swift +23 -0
  21. package/lib/PylonChatView.d.ts +27 -0
  22. package/lib/PylonChatView.js +78 -0
  23. package/lib/PylonChatWidget.android.d.ts +19 -0
  24. package/lib/PylonChatWidget.android.js +144 -0
  25. package/lib/PylonChatWidget.ios.d.ts +14 -0
  26. package/lib/PylonChatWidget.ios.js +79 -0
  27. package/lib/PylonModule.d.ts +32 -0
  28. package/lib/PylonModule.js +44 -0
  29. package/lib/index.d.ts +5 -0
  30. package/lib/index.js +15 -0
  31. package/lib/types.d.ts +34 -0
  32. package/lib/types.js +2 -0
  33. package/package.json +39 -0
  34. package/src/PylonChatView.tsx +170 -0
  35. package/src/PylonChatWidget.android.tsx +165 -0
  36. package/src/PylonChatWidget.d.ts +15 -0
  37. package/src/PylonChatWidget.ios.tsx +79 -0
  38. package/src/PylonModule.ts +52 -0
  39. package/src/index.ts +15 -0
  40. package/src/types.ts +37 -0
@@ -0,0 +1,201 @@
1
+ package com.pylonchat.reactnative
2
+
3
+ import android.graphics.Color
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.ReadableArray
6
+ import com.facebook.react.bridge.ReadableMap
7
+ import com.facebook.react.common.MapBuilder
8
+ import com.facebook.react.uimanager.SimpleViewManager
9
+ import com.facebook.react.uimanager.ThemedReactContext
10
+ import com.facebook.react.uimanager.annotations.ReactProp
11
+ import com.facebook.react.uimanager.events.RCTEventEmitter
12
+ import com.pylon.chatwidget.PylonChatListener
13
+ import com.pylon.chatwidget.PylonChatView
14
+ import com.pylon.chatwidget.PylonConfig
15
+ import com.pylon.chatwidget.PylonUser
16
+
17
+ class RNPylonChatViewManager : SimpleViewManager<RNPylonChatView>() {
18
+
19
+ companion object {
20
+ const val REACT_CLASS = "RNPylonChatView"
21
+ const val COMMAND_OPEN_CHAT = 1
22
+ const val COMMAND_CLOSE_CHAT = 2
23
+ const val COMMAND_SHOW_BUBBLE = 3
24
+ const val COMMAND_HIDE_BUBBLE = 4
25
+ const val COMMAND_SHOW_NEW_MESSAGE = 5
26
+ const val COMMAND_SET_CUSTOM_FIELDS = 6
27
+ const val COMMAND_SET_TICKET_FIELDS = 7
28
+ const val COMMAND_UPDATE_EMAIL_HASH = 8
29
+ const val COMMAND_SHOW_TICKET_FORM = 9
30
+ const val COMMAND_SHOW_KB_ARTICLE = 10
31
+ const val COMMAND_CLICK_ELEMENT_AT_SELECTOR = 11
32
+ }
33
+
34
+ override fun getName(): String = REACT_CLASS
35
+
36
+ override fun createViewInstance(reactContext: ThemedReactContext): RNPylonChatView {
37
+ return RNPylonChatView(reactContext)
38
+ }
39
+
40
+ // Config props
41
+ @ReactProp(name = "appId")
42
+ fun setAppId(view: RNPylonChatView, appId: String?) {
43
+ view.appId = appId
44
+ }
45
+
46
+ @ReactProp(name = "widgetBaseUrl")
47
+ fun setWidgetBaseUrl(view: RNPylonChatView, url: String?) {
48
+ view.widgetBaseUrl = url
49
+ }
50
+
51
+ @ReactProp(name = "widgetScriptUrl")
52
+ fun setWidgetScriptUrl(view: RNPylonChatView, url: String?) {
53
+ view.widgetScriptUrl = url
54
+ }
55
+
56
+ @ReactProp(name = "enableLogging")
57
+ fun setEnableLogging(view: RNPylonChatView, enabled: Boolean) {
58
+ view.enableLogging = enabled
59
+ }
60
+
61
+ @ReactProp(name = "debugMode")
62
+ fun setDebugMode(view: RNPylonChatView, enabled: Boolean) {
63
+ view.debugMode = enabled
64
+ }
65
+
66
+ @ReactProp(name = "pointerEvents")
67
+ fun setPointerEvents(view: RNPylonChatView, pointerEvents: String?) {
68
+ val mode = pointerEvents ?: "auto"
69
+ view.setPointerEventsMode(mode)
70
+
71
+ when (mode) {
72
+ "none" -> {
73
+ // Don't handle any touches - let them pass through
74
+ view.isClickable = false
75
+ view.isFocusable = false
76
+ }
77
+ "auto" -> {
78
+ // Handle touches normally
79
+ view.isClickable = true
80
+ view.isFocusable = true
81
+ }
82
+ "box-none" -> {
83
+ // Only children can handle touches, not this view itself
84
+ view.isClickable = false
85
+ view.isFocusable = false
86
+ }
87
+ "box-only" -> {
88
+ // Only this view handles touches, not children
89
+ view.isClickable = true
90
+ view.isFocusable = true
91
+ }
92
+ }
93
+ }
94
+
95
+ @ReactProp(name = "primaryColor")
96
+ fun setPrimaryColor(view: RNPylonChatView, color: String?) {
97
+ view.primaryColor = color
98
+ }
99
+
100
+ // User props
101
+ @ReactProp(name = "userEmail")
102
+ fun setUserEmail(view: RNPylonChatView, email: String?) {
103
+ view.userEmail = email
104
+ }
105
+
106
+ @ReactProp(name = "userName")
107
+ fun setUserName(view: RNPylonChatView, name: String?) {
108
+ view.userName = name
109
+ }
110
+
111
+ @ReactProp(name = "userAvatarUrl")
112
+ fun setUserAvatarUrl(view: RNPylonChatView, url: String?) {
113
+ view.userAvatarUrl = url
114
+ }
115
+
116
+ @ReactProp(name = "userEmailHash")
117
+ fun setUserEmailHash(view: RNPylonChatView, hash: String?) {
118
+ view.userEmailHash = hash
119
+ }
120
+
121
+ @ReactProp(name = "userAccountId")
122
+ fun setUserAccountId(view: RNPylonChatView, id: String?) {
123
+ view.userAccountId = id
124
+ }
125
+
126
+ @ReactProp(name = "userAccountExternalId")
127
+ fun setUserAccountExternalId(view: RNPylonChatView, id: String?) {
128
+ view.userAccountExternalId = id
129
+ }
130
+
131
+ // Event names
132
+ override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
133
+ return MapBuilder.builder<String, Any>()
134
+ .put("onPylonLoaded", MapBuilder.of("registrationName", "onPylonLoaded"))
135
+ .put("onPylonInitialized", MapBuilder.of("registrationName", "onPylonInitialized"))
136
+ .put("onPylonReady", MapBuilder.of("registrationName", "onPylonReady"))
137
+ .put("onChatOpened", MapBuilder.of("registrationName", "onChatOpened"))
138
+ .put("onChatClosed", MapBuilder.of("registrationName", "onChatClosed"))
139
+ .put("onUnreadCountChanged", MapBuilder.of("registrationName", "onUnreadCountChanged"))
140
+ .put("onMessageReceived", MapBuilder.of("registrationName", "onMessageReceived"))
141
+ .put("onPylonError", MapBuilder.of("registrationName", "onPylonError"))
142
+ .put("onInteractiveBoundsChanged", MapBuilder.of("registrationName", "onInteractiveBoundsChanged"))
143
+ .build() as MutableMap<String, Any>
144
+ }
145
+
146
+ // Commands
147
+ override fun getCommandsMap(): MutableMap<String, Int> {
148
+ return MapBuilder.builder<String, Int>()
149
+ .put("openChat", COMMAND_OPEN_CHAT)
150
+ .put("closeChat", COMMAND_CLOSE_CHAT)
151
+ .put("showChatBubble", COMMAND_SHOW_BUBBLE)
152
+ .put("hideChatBubble", COMMAND_HIDE_BUBBLE)
153
+ .put("showNewMessage", COMMAND_SHOW_NEW_MESSAGE)
154
+ .put("setNewIssueCustomFields", COMMAND_SET_CUSTOM_FIELDS)
155
+ .put("setTicketFormFields", COMMAND_SET_TICKET_FIELDS)
156
+ .put("updateEmailHash", COMMAND_UPDATE_EMAIL_HASH)
157
+ .put("showTicketForm", COMMAND_SHOW_TICKET_FORM)
158
+ .put("showKnowledgeBaseArticle", COMMAND_SHOW_KB_ARTICLE)
159
+ .put("clickElementAtSelector", COMMAND_CLICK_ELEMENT_AT_SELECTOR)
160
+ .build() as MutableMap<String, Int>
161
+ }
162
+
163
+ override fun receiveCommand(view: RNPylonChatView, commandId: String, args: ReadableArray?) {
164
+ when (commandId) {
165
+ "openChat" -> view.openChat()
166
+ "closeChat" -> view.closeChat()
167
+ "showChatBubble" -> view.showChatBubble()
168
+ "hideChatBubble" -> view.hideChatBubble()
169
+ "showNewMessage" -> {
170
+ val message = args?.getString(0) ?: return
171
+ val isHtml = args.getBoolean(1)
172
+ view.showNewMessage(message, isHtml)
173
+ }
174
+ "setNewIssueCustomFields" -> {
175
+ val fields = args?.getMap(0) ?: return
176
+ view.setNewIssueCustomFields(fields.toHashMap())
177
+ }
178
+ "setTicketFormFields" -> {
179
+ val fields = args?.getMap(0) ?: return
180
+ view.setTicketFormFields(fields.toHashMap())
181
+ }
182
+ "updateEmailHash" -> {
183
+ val hash = args?.getString(0)
184
+ view.updateEmailHash(hash)
185
+ }
186
+ "showTicketForm" -> {
187
+ val slug = args?.getString(0) ?: return
188
+ view.showTicketForm(slug)
189
+ }
190
+ "showKnowledgeBaseArticle" -> {
191
+ val articleId = args?.getString(0) ?: return
192
+ view.showKnowledgeBaseArticle(articleId)
193
+ }
194
+ "clickElementAtSelector" -> {
195
+ val selector = args?.getString(0) ?: return
196
+ view.clickElementAtSelector(selector)
197
+ }
198
+ }
199
+ }
200
+ }
201
+