Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 5f6ed4c

Browse files
authored
Android ReactEditTextImproved implementation (#13)
* adding ReactEditTextImproved native API * patch renderer to add RCTTextInputImproved * basic TextInput example * patch rn api to point to custom ReactTextInputImprovedManager * adding TextInputViewManager with RN API * complete implementation of TextInput patch
1 parent 9ecdde4 commit 5f6ed4c

File tree

9 files changed

+864
-1
lines changed

9 files changed

+864
-1
lines changed

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def supportsNamespace() {
3939
android {
4040
if (supportsNamespace()) {
4141
namespace "com.text"
42+
namespace "com.textinput"
4243

4344
sourceSets {
4445
main {

android/src/main/java/com/text/TextViewPackage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.facebook.react.bridge.NativeModule;
66
import com.facebook.react.bridge.ReactApplicationContext;
77
import com.facebook.react.uimanager.ViewManager;
8+
import com.textinput.ReactTextInputImprovedManager;
89

910
import java.util.ArrayList;
1011
import java.util.Collections;
@@ -15,6 +16,7 @@ public class TextViewPackage implements ReactPackage {
1516
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
1617
List<ViewManager> viewManagers = new ArrayList<>();
1718
viewManagers.add(new ReactTextViewImprovedManager());
19+
viewManagers.add(new ReactTextInputImprovedManager());
1820
return viewManagers;
1921
}
2022

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.textinput;
9+
10+
import android.util.Log;
11+
import com.facebook.react.bridge.ReactContext;
12+
import com.facebook.react.views.text.ReactTextUpdate;
13+
import com.facebook.react.views.textinput.ReactEditText;
14+
15+
public class ReactEditTextImproved extends ReactEditText {
16+
17+
public ReactEditTextImproved(ReactContext context) {
18+
super(context);
19+
}
20+
21+
public void maybeSetText(ReactTextUpdate reactTextUpdate) {
22+
super.maybeSetText(reactTextUpdate);
23+
Log.w("TESTING", "ReactEditTextImproved => maybeSetText");
24+
}
25+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.textinput;
9+
10+
import androidx.annotation.Nullable;
11+
import com.facebook.react.module.annotations.ReactModule;
12+
import com.facebook.react.uimanager.ThemedReactContext;
13+
import com.facebook.react.views.text.ReactTextViewManagerCallback;
14+
import com.facebook.react.views.textinput.ReactEditText;
15+
import com.facebook.react.views.textinput.ReactTextInputManager;
16+
17+
@ReactModule(name = ReactTextInputImprovedManager.NAME)
18+
public class ReactTextInputImprovedManager extends ReactTextInputManager {
19+
public static final String NAME = "RCTTextInputImproved";
20+
protected @Nullable ReactTextViewManagerCallback mReactTextViewManagerCallback;
21+
22+
@Override
23+
public String getName() {
24+
return NAME;
25+
}
26+
27+
/*
28+
public ReactTextInputImprovedManager() {
29+
this(null);
30+
}
31+
32+
33+
public ReactTextInputImprovedManager(
34+
@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
35+
super(reactTextViewManagerCallback);
36+
}
37+
*/
38+
39+
@Override
40+
public ReactEditText createViewInstance(ThemedReactContext context) {
41+
return new ReactEditTextImproved(context);
42+
}
43+
}

example/src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22

33
import { ScrollView, View, StyleSheet, Text, TextInput } from 'react-native';
44
import { TextScreen } from './TextScreen';
5+
import { TextInputScreen } from './TextInputScreen';
56

67
export default function App() {
78
const email =
@@ -10,7 +11,8 @@ export default function App() {
1011
}
1112

1213
function CurrentScreen() {
13-
return <TextScreen />;
14+
// return <TextScreen />;
15+
return <TextInputScreen />;
1416
}
1517

1618
const styles = StyleSheet.create({});

example/src/TextInputScreen.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as React from 'react';
2+
import { View, TextInput, StyleSheet } from 'react-native';
3+
4+
export function TextInputScreen() {
5+
const [text, setText] = React.useState('');
6+
return (
7+
<View style={styles.container}>
8+
<TextInput
9+
onChangeText={(text) => {
10+
console.log('onChangeText text is: ', text);
11+
setText(text);
12+
}}
13+
style={styles.input}
14+
>
15+
{text}
16+
</TextInput>
17+
</View>
18+
);
19+
}
20+
21+
const styles = StyleSheet.create({
22+
container: {
23+
marginTop: 100,
24+
},
25+
input: {
26+
borderWidth: 1,
27+
height: 100,
28+
width: 400,
29+
},
30+
});

0 commit comments

Comments
 (0)