-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #574 from DataDog/jmoskovich/rum-1817/android-masking
Implement Masking for Android SR text
- Loading branch information
Showing
13 changed files
with
239 additions
and
95 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
54 changes: 54 additions & 0 deletions
54
...src/main/kotlin/com/datadog/reactnative/sessionreplay/mappers/ReactMaskInputTextMapper.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,54 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.reactnative.sessionreplay.mappers | ||
|
||
import android.widget.TextView | ||
import com.datadog.android.sessionreplay.internal.AsyncJobStatusCallback | ||
import com.datadog.android.sessionreplay.internal.recorder.MappingContext | ||
import com.datadog.android.sessionreplay.internal.recorder.mapper.MaskInputTextViewMapper | ||
import com.datadog.android.sessionreplay.model.MobileSegment | ||
import com.datadog.reactnative.sessionreplay.NoopTextPropertiesResolver | ||
import com.datadog.reactnative.sessionreplay.ReactTextPropertiesResolver | ||
import com.datadog.reactnative.sessionreplay.TextPropertiesResolver | ||
import com.datadog.reactnative.sessionreplay.utils.TextViewUtils | ||
import com.facebook.react.bridge.ReactContext | ||
import com.facebook.react.uimanager.UIManagerModule | ||
|
||
internal class ReactMaskInputTextMapper( | ||
private val reactTextPropertiesResolver: TextPropertiesResolver, | ||
private val textViewUtils: TextViewUtils = TextViewUtils() | ||
): MaskInputTextViewMapper() { | ||
|
||
internal constructor( | ||
reactContext: ReactContext, | ||
uiManagerModule: UIManagerModule? | ||
): this( | ||
reactTextPropertiesResolver = if (uiManagerModule == null) { | ||
NoopTextPropertiesResolver() | ||
} else { | ||
ReactTextPropertiesResolver( | ||
reactContext = reactContext, | ||
uiManagerModule = uiManagerModule | ||
) | ||
} | ||
) | ||
|
||
override fun map( | ||
view: TextView, | ||
mappingContext: MappingContext, | ||
asyncJobStatusCallback: AsyncJobStatusCallback | ||
): List<MobileSegment.Wireframe> { | ||
val wireframes = super.map(view, mappingContext, asyncJobStatusCallback) | ||
return textViewUtils.mapTextViewToWireframes( | ||
wireframes = wireframes, | ||
view = view, | ||
mappingContext = mappingContext, | ||
reactTextPropertiesResolver = reactTextPropertiesResolver | ||
) | ||
} | ||
} | ||
|
55 changes: 55 additions & 0 deletions
55
...roid/src/main/kotlin/com/datadog/reactnative/sessionreplay/mappers/ReactMaskTextMapper.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,55 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.reactnative.sessionreplay.mappers | ||
|
||
import android.widget.TextView | ||
import com.datadog.android.sessionreplay.internal.AsyncJobStatusCallback | ||
import com.datadog.android.sessionreplay.internal.recorder.MappingContext | ||
import com.datadog.android.sessionreplay.internal.recorder.mapper.MaskTextViewMapper | ||
import com.datadog.android.sessionreplay.model.MobileSegment | ||
import com.datadog.reactnative.sessionreplay.NoopTextPropertiesResolver | ||
import com.datadog.reactnative.sessionreplay.ReactTextPropertiesResolver | ||
import com.datadog.reactnative.sessionreplay.TextPropertiesResolver | ||
import com.datadog.reactnative.sessionreplay.utils.TextViewUtils | ||
import com.facebook.react.bridge.ReactContext | ||
import com.facebook.react.uimanager.UIManagerModule | ||
|
||
internal class ReactMaskTextMapper( | ||
private val reactTextPropertiesResolver: TextPropertiesResolver = | ||
NoopTextPropertiesResolver(), | ||
private val textViewUtils: TextViewUtils = TextViewUtils() | ||
): MaskTextViewMapper() { | ||
|
||
internal constructor( | ||
reactContext: ReactContext, | ||
uiManagerModule: UIManagerModule? | ||
): this( | ||
reactTextPropertiesResolver = if (uiManagerModule == null) { | ||
NoopTextPropertiesResolver() | ||
} else { | ||
ReactTextPropertiesResolver( | ||
reactContext = reactContext, | ||
uiManagerModule = uiManagerModule | ||
) | ||
} | ||
) | ||
|
||
override fun map( | ||
view: TextView, | ||
mappingContext: MappingContext, | ||
asyncJobStatusCallback: AsyncJobStatusCallback | ||
): List<MobileSegment.Wireframe> { | ||
val wireframes = super.map(view, mappingContext, asyncJobStatusCallback) | ||
return textViewUtils.mapTextViewToWireframes( | ||
wireframes = wireframes, | ||
view = view, | ||
mappingContext = mappingContext, | ||
reactTextPropertiesResolver = reactTextPropertiesResolver | ||
) | ||
} | ||
} | ||
|
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
40 changes: 40 additions & 0 deletions
40
...play/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/utils/TextViewUtils.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,40 @@ | ||
/* | ||
* | ||
* * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* * This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* * Copyright 2016-Present Datadog, Inc. | ||
* | ||
*/ | ||
|
||
package com.datadog.reactnative.sessionreplay.utils | ||
|
||
import android.widget.TextView | ||
import com.datadog.android.sessionreplay.internal.recorder.MappingContext | ||
import com.datadog.android.sessionreplay.model.MobileSegment | ||
import com.datadog.reactnative.sessionreplay.TextPropertiesResolver | ||
|
||
internal class TextViewUtils { | ||
internal fun mapTextViewToWireframes( | ||
wireframes: List<MobileSegment.Wireframe>, | ||
view: TextView, | ||
mappingContext: MappingContext, | ||
reactTextPropertiesResolver: TextPropertiesResolver | ||
): List<MobileSegment.Wireframe> { | ||
val result = mutableListOf<MobileSegment.Wireframe>() | ||
val pixelDensity = mappingContext.systemInformation.screenDensity | ||
|
||
wireframes.forEach { originalWireframe -> | ||
if (originalWireframe !is MobileSegment.Wireframe.TextWireframe) { | ||
result.add(originalWireframe) | ||
} else { | ||
result.add(reactTextPropertiesResolver.addReactNativeProperties( | ||
originalWireframe = originalWireframe, | ||
view = view, | ||
pixelDensity = pixelDensity, | ||
)) | ||
} | ||
} | ||
|
||
return result | ||
} | ||
} |
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.