-
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 5d0c7e1
Showing
11 changed files
with
272 additions
and
79 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
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 = | ||
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> { | ||
return textViewUtils.mapTextViewToWireframes( | ||
mapper = this, | ||
view = view, | ||
mappingContext = mappingContext, | ||
asyncJobStatusCallback = asyncJobStatusCallback, | ||
reactTextPropertiesResolver = reactTextPropertiesResolver | ||
) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...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,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.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> { | ||
return textViewUtils.mapTextViewToWireframes( | ||
mapper = this, | ||
view = view, | ||
mappingContext = mappingContext, | ||
asyncJobStatusCallback = asyncJobStatusCallback, | ||
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
61 changes: 61 additions & 0 deletions
61
...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,61 @@ | ||
/* | ||
* | ||
* * 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 androidx.annotation.VisibleForTesting | ||
import com.datadog.android.sessionreplay.internal.AsyncJobStatusCallback | ||
import com.datadog.android.sessionreplay.internal.recorder.MappingContext | ||
import com.datadog.android.sessionreplay.internal.recorder.mapper.WireframeMapper | ||
import com.datadog.android.sessionreplay.model.MobileSegment | ||
import com.datadog.reactnative.sessionreplay.TextPropertiesResolver | ||
|
||
internal class TextViewUtils { | ||
internal fun mapTextViewToWireframes( | ||
mapper: WireframeMapper<TextView, MobileSegment.Wireframe>, | ||
view: TextView, | ||
mappingContext: MappingContext, | ||
asyncJobStatusCallback: AsyncJobStatusCallback, | ||
reactTextPropertiesResolver: TextPropertiesResolver | ||
): List<MobileSegment.Wireframe> { | ||
val result = mutableListOf<MobileSegment.Wireframe>() | ||
val pixelDensity = mappingContext.systemInformation.screenDensity | ||
|
||
val wireframes = mapOnSuperclass( | ||
mapper = mapper, | ||
textView = view, | ||
mappingContext = mappingContext, | ||
asyncJobStatusCallback = asyncJobStatusCallback | ||
) | ||
|
||
wireframes.forEach { originalWireframe -> | ||
if (originalWireframe !is MobileSegment.Wireframe.TextWireframe) { | ||
result.add(originalWireframe) | ||
} else { | ||
result.add(reactTextPropertiesResolver.addReactNativeProperties( | ||
originalWireframe = originalWireframe, | ||
view = view, | ||
pixelDensity = pixelDensity, | ||
)) | ||
} | ||
} | ||
|
||
return wireframes | ||
} | ||
|
||
@VisibleForTesting | ||
internal fun mapOnSuperclass( | ||
mapper: WireframeMapper<TextView, MobileSegment.Wireframe>, | ||
textView: TextView, | ||
mappingContext: MappingContext, | ||
asyncJobStatusCallback: AsyncJobStatusCallback | ||
): List<MobileSegment.Wireframe> { | ||
return mapper.map(textView, mappingContext, asyncJobStatusCallback) | ||
} | ||
} |
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.