-
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.
Implement masking for Android SR ReactTextView and ReactEditText
- Loading branch information
1 parent
7cc8400
commit b75d175
Showing
11 changed files
with
239 additions
and
93 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
55 changes: 55 additions & 0 deletions
55
...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,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.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 = | ||
NoopTextPropertiesResolver(), | ||
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.