Skip to content

Commit

Permalink
Feat: new arch support (#7)
Browse files Browse the repository at this point in the history
* feat: add new arch support

* fix: apply ktlint

* fix: apply swiftformat

* fix: fix after rebase

* fix: remove recursion from findFirstTextField

* feat: use one swift class for fabric and paper

* fix: don't set value if text is the same

* fix: apply ktlint

* fix: build for iOS

* fix: iOS build

* fix: always install cocoapods
  • Loading branch information
IvanIhnatsiuk authored Oct 27, 2024
1 parent dc2d667 commit 8e28d98
Show file tree
Hide file tree
Showing 22 changed files with 582 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
${{ runner.os }}-cocoapods-
- name: Install cocoapods
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
# if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
yarn pod-install example/ios
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import com.facebook.react.ReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager
import com.maskedtextinput.managers.MaskedTextInputDecoratorViewManager
import com.maskedtextinput.managers.AdvancedTextInputMaskDecoratorViewManager

class MaskedTextInputPackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> = emptyList()

override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
listOf(MaskedTextInputDecoratorViewManager(reactContext))
listOf(AdvancedTextInputMaskDecoratorViewManager(reactContext))
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.maskedtextinput.events

object EventNames {
const val CHANGE_TEXT_EVENT = "changeText"
const val CHANGE_TEXT_EVENT = "onAdvancedMaskTextChange"
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
package com.maskedtextinput.managers

import android.view.View
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.common.MapBuilder
import com.facebook.react.common.MapBuilder.newHashMap
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.annotations.ReactProp
import com.maskedtextinput.AdvancedTextInputMaskDecoratorViewManagerSpec
import com.maskedtextinput.events.EventNames
import com.maskedtextinput.mappers.AffinityCalculationStrategyMapper
import com.maskedtextinput.mappers.NotationMapper
import com.maskedtextinput.views.MaskedTextInputDecoratorView
import com.maskedtextinput.views.AdvancedTextInputMaskDecoratorView

class MaskedTextInputDecoratorViewManager(
class AdvancedTextInputMaskDecoratorViewManager(
private val callerContext: ReactApplicationContext,
) : SimpleViewManager<View>() {
) : AdvancedTextInputMaskDecoratorViewManagerSpec<AdvancedTextInputMaskDecoratorView>() {
override fun getName() = NAME

override fun createViewInstance(context: ThemedReactContext) = MaskedTextInputDecoratorView(context)
override fun createViewInstance(context: ThemedReactContext) = AdvancedTextInputMaskDecoratorView(context)

@ReactProp(name = "primaryMaskFormat")
fun setMask(
view: MaskedTextInputDecoratorView,
mask: String,
override fun setPrimaryMaskFormat(
view: AdvancedTextInputMaskDecoratorView,
value: String?,
) {
view.setMask(mask)
if (value != null) {
view.setMask(value)
}
}

@ReactProp(name = "customNotations")
fun setCustomNotations(
view: MaskedTextInputDecoratorView,
override fun setCustomNotations(
view: AdvancedTextInputMaskDecoratorView,
customNotation: ReadableArray?,
) {
val notationsList = customNotation?.let { NotationMapper().fromReadableArray(it) }
Expand All @@ -41,34 +42,32 @@ class MaskedTextInputDecoratorViewManager(
}

@ReactProp(name = "defaultValue")
fun setDefaultValue(
view: MaskedTextInputDecoratorView,
override fun setDefaultValue(
view: AdvancedTextInputMaskDecoratorView,
defaultValue: String?,
) {
view.setDefaultValue(defaultValue)
}

@ReactProp(name = "value")
fun setValue(
view: MaskedTextInputDecoratorView,
override fun setValue(
view: AdvancedTextInputMaskDecoratorView,
value: String?,
) {
view.setValue(value)
}

@ReactProp(name = "affinityCalculationStrategy")
fun setAffinityCalculationStrategy(
view: MaskedTextInputDecoratorView,
affinityCalculationStrategy: Int?,
override fun setAffinityCalculationStrategy(
view: AdvancedTextInputMaskDecoratorView,
affinityCalculationStrategy: Int,
) {
if (affinityCalculationStrategy != null) {
view.setAffinityCalculationStrategy(AffinityCalculationStrategyMapper().fromInt(affinityCalculationStrategy))
}
view.setAffinityCalculationStrategy(AffinityCalculationStrategyMapper().fromInt(affinityCalculationStrategy))
}

@ReactProp(name = "affinityFormat")
fun setAffinityFormat(
view: MaskedTextInputDecoratorView,
override fun setAffinityFormat(
view: AdvancedTextInputMaskDecoratorView,
affinityFormat: ReadableArray?,
) {
if (affinityFormat != null) {
Expand All @@ -83,35 +82,33 @@ class MaskedTextInputDecoratorViewManager(
}

@ReactProp(name = "isRTL")
fun setRTL(
view: MaskedTextInputDecoratorView,
isRTL: Boolean?,
override fun setIsRTL(
view: AdvancedTextInputMaskDecoratorView,
isRTL: Boolean,
) {
if (isRTL != null) {
view.setIsRtl(isRTL)
}
view.setIsRtl(isRTL)
}

@ReactProp(name = "autoSkip")
fun setAutoSkip(
view: MaskedTextInputDecoratorView,
autoSkip: Boolean = false,
override fun setAutoSkip(
view: AdvancedTextInputMaskDecoratorView,
autoSkip: Boolean,
) {
view.setAutoSkip(autoSkip)
}

@ReactProp(name = "autocomplete")
fun setAutoComplete(
view: MaskedTextInputDecoratorView,
autocomplete: Boolean = false,
override fun setAutocomplete(
view: AdvancedTextInputMaskDecoratorView,
autocomplete: Boolean,
) {
view.setAutoComplete(autocomplete)
}

@ReactProp(name = "customTransformation")
fun setCustomTransformation(
view: MaskedTextInputDecoratorView,
customTransformation: ReadableMap? = null,
override fun setCustomTransformation(
view: AdvancedTextInputMaskDecoratorView,
customTransformation: ReadableMap?,
) {
view.setCustomTransformationMethod(customTransformation)
}
Expand All @@ -124,7 +121,19 @@ class MaskedTextInputDecoratorViewManager(
return export
}

override fun setAllowSuggestions(
view: AdvancedTextInputMaskDecoratorView?,
value: Boolean,
) {
}

override fun setAutocompleteOnFocus(
view: AdvancedTextInputMaskDecoratorView?,
value: Boolean,
) {
}

companion object {
const val NAME = "MaskedTextInputDecoratorView"
const val NAME = "AdvancedTextInputMaskDecoratorView"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.redmadrobot.inputmask.MaskedTextChangedListener
import com.redmadrobot.inputmask.helper.AffinityCalculationStrategy
import com.redmadrobot.inputmask.model.Notation

class MaskedTextInputDecoratorView(
class AdvancedTextInputMaskDecoratorView(
context: Context,
) : View(context) {
private var textField: ReactEditText? = null
Expand Down Expand Up @@ -58,7 +58,9 @@ class MaskedTextInputDecoratorView(
if (previousSibling is ReactEditText) {
textField = previousSibling
textField?.let {
it.transformationMethod = customTransformationMethod
if (customTransformationMethod != null) {
it.transformationMethod = customTransformationMethod
}
maskedTextChangeListener =
ReactMaskedTextChangeListener.installOn(
field = it,
Expand All @@ -75,14 +77,6 @@ class MaskedTextInputDecoratorView(
}
}

override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
if (textField != null) {
textField = null
maskFormat = ""
}
}

fun setMask(format: String) {
maskFormat = format
maskedTextChangeListener?.primaryFormat = format
Expand Down Expand Up @@ -124,9 +118,9 @@ class MaskedTextInputDecoratorView(
}

fun setValue(value: String?) {
maskedTextChangeListener?.autocomplete = false
value?.let { maskedTextChangeListener?.setText(it) }
maskedTextChangeListener?.autocomplete = autocomplete
if (textField?.text.toString() != value) {
value?.let { maskedTextChangeListener?.setText(it) }
}
}

fun setCustomTransformationMethod(transformationMethod: ReadableMap?) {
Expand Down
12 changes: 0 additions & 12 deletions android/src/main/oldarch/MaskedTextInputDecoratorViewSpec.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.maskedtextinput

import android.view.View
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.viewmanagers.AdvancedTextInputMaskDecoratorViewManagerDelegate
import com.facebook.react.viewmanagers.AdvancedTextInputMaskDecoratorViewManagerInterface

abstract class AdvancedTextInputMaskDecoratorViewManagerSpec<T : View?> :
SimpleViewManager<T>(),
AdvancedTextInputMaskDecoratorViewManagerInterface<T> {
private val mDelegate: ViewManagerDelegate<T> = AdvancedTextInputMaskDecoratorViewManagerDelegate(this)

override fun getDelegate(): ViewManagerDelegate<T>? = mDelegate
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.maskedtextinput

import android.view.View
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.uimanager.SimpleViewManager

abstract class AdvancedTextInputMaskDecoratorViewManagerSpec<T : View?> : SimpleViewManager<T>() {
abstract fun setPrimaryMaskFormat(
view: T,
mask: String?,
)

abstract fun setCustomNotations(
view: T,
customNotation: ReadableArray?,
)

abstract fun setDefaultValue(
view: T,
defaultValue: String?,
)

abstract fun setValue(
view: T,
value: String?,
)

abstract fun setAffinityCalculationStrategy(
view: T,
affinityCalculationStrategy: Int,
)

abstract fun setAffinityFormat(
view: T,
affinityFormat: ReadableArray?,
)

abstract fun setIsRTL(
view: T,
isRTL: Boolean = false,
)

abstract fun setAutoSkip(
view: T,
autoSkip: Boolean = false,
)

abstract fun setAutocomplete(
view: T,
autocomplete: Boolean = false,
)

abstract fun setCustomTransformation(
view: T,
customTransformation: ReadableMap? = null,
)

abstract fun setAllowSuggestions(
view: T?,
value: Boolean,
)

abstract fun setAutocompleteOnFocus(
view: T?,
value: Boolean,
)
}
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
newArchEnabled=false
newArchEnabled=true

# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
Expand Down
12 changes: 10 additions & 2 deletions example/ios/MaskedTextInputExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -576,13 +576,17 @@
);
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "$(inherited)";
OTHER_CFLAGS = (
"$(inherited)",
" ",
);
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-DFOLLY_NO_CONFIG",
"-DFOLLY_MOBILE=1",
"-DFOLLY_USE_LIBCPP=1",
"-DFOLLY_CFG_NO_COROUTINES=1",
" ",
);
OTHER_LDFLAGS = (
"$(inherited)",
Expand Down Expand Up @@ -647,13 +651,17 @@
"\"$(inherited)\"",
);
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CFLAGS = "$(inherited)";
OTHER_CFLAGS = (
"$(inherited)",
" ",
);
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-DFOLLY_NO_CONFIG",
"-DFOLLY_MOBILE=1",
"-DFOLLY_USE_LIBCPP=1",
"-DFOLLY_CFG_NO_COROUTINES=1",
" ",
);
OTHER_LDFLAGS = (
"$(inherited)",
Expand Down
Loading

0 comments on commit 8e28d98

Please sign in to comment.