-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
5,089 additions
and
4,250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
android/src/main/java/com/exponea/widget/InAppContentBlocksPlaceholderManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.exponea.widget | ||
|
||
import android.content.Context | ||
import android.widget.LinearLayout | ||
import com.exponea.sdk.Exponea | ||
import com.exponea.sdk.models.InAppContentBlockPlaceholderConfiguration | ||
import com.exponea.sdk.util.Logger | ||
import com.exponea.sdk.view.InAppContentBlockPlaceholderView | ||
import com.facebook.react.bridge.Arguments | ||
import com.facebook.react.common.MapBuilder | ||
import com.facebook.react.uimanager.PixelUtil | ||
import com.facebook.react.uimanager.SimpleViewManager | ||
import com.facebook.react.uimanager.ThemedReactContext | ||
import com.facebook.react.uimanager.annotations.ReactProp | ||
import com.facebook.react.uimanager.events.RCTEventEmitter | ||
|
||
class InAppContentBlocksPlaceholderManager : SimpleViewManager<InAppContentBlocksPlaceholder>() { | ||
|
||
override fun getName() = "RNInAppContentBlocksPlaceholder" | ||
|
||
override fun createViewInstance(reactContext: ThemedReactContext): InAppContentBlocksPlaceholder { | ||
val container = InAppContentBlocksPlaceholder(reactContext) | ||
container.setOnDimensChangedListener { width, height -> | ||
Logger.i(this, "InAppCB: Size changed with w${width}px h${height}px") | ||
val widthInDp = PixelUtil.toDIPFromPixel(width.toFloat()) | ||
val heightInDp = PixelUtil.toDIPFromPixel(height.toFloat()) | ||
notifyDimensChanged(reactContext, container.id, widthInDp, heightInDp) | ||
} | ||
return container | ||
} | ||
|
||
@ReactProp(name = "placeholderId") | ||
fun setPlaceholderId(placeholderContainer: InAppContentBlocksPlaceholder, newPlaceholderId: String?) { | ||
placeholderContainer.setPlaceholderId(newPlaceholderId) | ||
} | ||
|
||
override fun getExportedCustomBubblingEventTypeConstants(): MutableMap<String, Any>? { | ||
val map = super.getExportedCustomBubblingEventTypeConstants() ?: MapBuilder.builder<String, Any>().build() | ||
map.put("dimensChanged", MapBuilder.of("phasedRegistrationNames", MapBuilder.of("bubbled", "onDimensChanged"))) | ||
return map | ||
} | ||
|
||
private fun notifyDimensChanged(context: ThemedReactContext, viewId: Int, width: Float, height: Float) { | ||
val event = Arguments.createMap().apply { | ||
putDouble("width", width.toDouble()) | ||
putDouble("height", height.toDouble()) | ||
} | ||
val eventEmitter = context.getJSModule(RCTEventEmitter::class.java) | ||
eventEmitter.receiveEvent(viewId, "dimensChanged", event) | ||
} | ||
} | ||
|
||
class InAppContentBlocksPlaceholder(context: Context?) : LinearLayout(context) { | ||
|
||
private var currentPlaceholderId: String? = null | ||
private var currentPlaceholderInstance: InAppContentBlockPlaceholderView? = null | ||
|
||
private var sizeChangedListener: ((Int, Int) -> Unit)? = null | ||
|
||
init { | ||
orientation = VERTICAL | ||
} | ||
|
||
fun setPlaceholderId(newPlaceholderId: String?) { | ||
if (currentPlaceholderId == newPlaceholderId && currentPlaceholderInstance != null) { | ||
// placeholderContainer holds same currentPlaceholderInstance | ||
currentPlaceholderInstance?.refreshContent() | ||
return | ||
} | ||
currentPlaceholderId = newPlaceholderId | ||
if (newPlaceholderId == null) { | ||
currentPlaceholderInstance = null | ||
} else { | ||
currentPlaceholderInstance = Exponea.getInAppContentBlocksPlaceholder( | ||
newPlaceholderId, context, InAppContentBlockPlaceholderConfiguration(true) | ||
) | ||
currentPlaceholderInstance?.let { registerContentLoadedListeners(it) } | ||
} | ||
this.removeAllViews() | ||
currentPlaceholderInstance?.let { | ||
val layoutParams = LayoutParams( | ||
LayoutParams.MATCH_PARENT, | ||
LayoutParams.WRAP_CONTENT | ||
) | ||
this.addView(it, layoutParams) | ||
} | ||
} | ||
|
||
private fun registerContentLoadedListeners(target: InAppContentBlockPlaceholderView) { | ||
target.setOnContentReadyListener { _ -> | ||
sizeChangedListener?.invoke(target.width, target.height) | ||
} | ||
} | ||
|
||
private val measureAndLayout = Runnable { | ||
measure( | ||
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), | ||
MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED) | ||
) | ||
Logger.i(this, "InAppCB: Measuring with $left $top $right $bottom") | ||
layout(left, top, right, bottom) | ||
} | ||
|
||
override fun requestLayout() { | ||
super.requestLayout() | ||
post(measureAndLayout) | ||
} | ||
|
||
fun setOnDimensChangedListener(listener: (Int, Int) -> Unit) { | ||
sizeChangedListener = listener | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: ['module:metro-react-native-babel-preset'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
## In-app content blocks | ||
Exponea SDK allows you to display native In-app content blocks based on definitions set up on the Exponea web application. You can find information on creating your messages in [Exponea documentation](https://documentation.bloomreach.com/engagement/docs/in-app-content-blocks) | ||
|
||
In-app content block will be shown exactly where you'll place a placeholder UI view. You can register a placeholder view into your layout: | ||
|
||
```typescript jsx | ||
<InAppContentBlocksPlaceholder | ||
style={{ | ||
width: '100%', | ||
}} | ||
placeholderId={'placeholder_1'} | ||
/> | ||
``` | ||
|
||
No more developer work is required; they work automatically after the SDK is initialized. | ||
In-app content blocks are shown within placeholder view by its ID automatically based on conditions setup on the Exponea backend. Once a message passes those filters, the SDK will try to present the message. | ||
|
||
### If displaying In-app content blocks has delay | ||
|
||
Message is able to be shown only if it is fully loaded and also its images are loaded too. In case that message is not yet fully loaded (including its images) then you may experience delayed showing. | ||
|
||
If you need to show In-app content block as soon as possible (ideally instantly) you may set a auto-prefetch of placeholders. In-app content blocks for these placeholders are loaded immediately after SDK initialization. | ||
|
||
```typescript jsx | ||
import Exponea from 'react-native-exponea-sdk' | ||
|
||
Exponea.configure({ | ||
// ... your configuration | ||
inAppContentBlockPlaceholdersAutoLoad: ['placeholder_1'], | ||
}).catch(error => console.log(error)) | ||
``` | ||
|
||
### In-app content block images caching | ||
To reduce the number of API calls, SDK is caching the images displayed in messages. Therefore, once the SDK downloads the image, an image with the same URL may not be downloaded again, and will not change, since it was already cached. For this reason, we recommend always using different URLs for different images. | ||
|
||
### In-app content blocks tracking | ||
|
||
In-app content blocks are tracked automatically by SDK. You may see these `action` values in customers tracked events: | ||
|
||
- 'show' - event is tracked if message has been shown to user | ||
- 'action' - event is tracked if user clicked on action button inside message. Event contains 'text' and 'link' properties that you might be interested in | ||
- 'close' - event is tracked if user clicked on close button inside message | ||
- 'error' - event is tracked if showing of message has failed. Event contains 'error' property with meaningfull description | ||
|
||
> The behaviour of In-app content block tracking may be affected by the tracking consent feature, which in enabled mode considers the requirement of explicit consent for tracking. Read more in [tracking consent documentation](./TRACKING_CONSENT.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.