Skip to content

Commit

Permalink
feat(android): add Text and TextInput features from 2.0 (#2526)
Browse files Browse the repository at this point in the history
* feat(android): feature from 2.0

- add breakStrategy prop for Text and TextInput
- add isFocused method for TextInput
- add ellipsizeMode prop support for Text componment

* feat(android): feature from 2.0

- revert demo

Co-authored-by: Zoom Chan <zoom_chan@163.com>
  • Loading branch information
iPel and zoomchan-cxj committed Oct 12, 2022
1 parent 5796f59 commit fea9add
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ trim_trailing_whitespace = true
max_line_length = 0
trim_trailing_whitespace = false

[*.java]
indent_size = 4

[COMMIT_EDITMSG]
max_line_length = 0
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class NodeProps {
public static final String LINE_SPACING_EXTRA = "lineSpacingExtra";
public static final String NUMBER_OF_LINES = "numberOfLines";
public static final String ELLIPSIZE_MODE = "ellipsizeMode";
public static final String BREAK_STRATEGY = "breakStrategy";
public static final String ON = "on";
public static final String RESIZE_MODE = "resizeMode";
public static final String RESIZE_METHOD = "resizeMethod";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,12 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return false;
}

public Map<String, Object> jsIsFocused() {
Map<String, Object> result = new HashMap<>();
result.put("value", hasFocus());
return result;
}

public void setBlurOrOnFocus(boolean blur) {
if (blur) {
setOnFocusChangeListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.Layout;
import android.text.TextUtils;
import android.text.method.PasswordTransformationMethod;
import android.util.TypedValue;
Expand All @@ -49,6 +50,7 @@
import com.tencent.renderer.NativeRender;
import com.tencent.renderer.NativeRenderException;
import com.tencent.renderer.NativeRendererManager;
import com.tencent.renderer.component.text.TextVirtualNode;
import com.tencent.renderer.utils.ArrayUtils;

import java.util.LinkedList;
Expand All @@ -71,6 +73,7 @@ public class HippyTextInputController extends HippyViewController<HippyTextInput
private static final String FUNC_CLEAR = "clear";
private static final String FUNC_FOCUS = "focusTextInput";
private static final String FUNC_BLUR = "blurTextInput";
private static final String FUNC_IS_FOCUSED = "isFocused";
private static final String FUNC_GET_VALUE = "getValue";
private static final String FUNC_SET_VALUE = "setValue";
private static final String FUNC_KEYBOARD_DISMISS = "dissmiss";
Expand Down Expand Up @@ -440,6 +443,26 @@ public void setTextAlignVertical(HippyTextInput view, String textAlignVertical)

}

@HippyControllerProps(name = NodeProps.BREAK_STRATEGY, defaultType = HippyControllerProps.STRING)
public void setBreakStrategy(HippyTextInput view, String strategy) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int strategyInt;
switch (strategy) {
case TextVirtualNode.STRATEGY_HIGH_QUALITY:
strategyInt = Layout.BREAK_STRATEGY_HIGH_QUALITY;
break;
case TextVirtualNode.STRATEGY_BALANCED:
strategyInt = Layout.BREAK_STRATEGY_BALANCED;
break;
case TextVirtualNode.STRATEGY_SIMPLE:
default:
strategyInt = Layout.BREAK_STRATEGY_SIMPLE;
}
// noinspection WrongConstant
view.setBreakStrategy(strategyInt);
}
}

@Override
public void dispatchFunction(@NonNull HippyTextInput textInput, @NonNull String functionName,
@NonNull HippyArray params, @NonNull Promise promise) {
Expand All @@ -449,8 +472,13 @@ public void dispatchFunction(@NonNull HippyTextInput textInput, @NonNull String
@Override
public void dispatchFunction(@NonNull final HippyTextInput textInput,
@NonNull String functionName, @NonNull List params, @NonNull Promise promise) {
if (FUNC_GET_VALUE.equals(functionName) && promise != null) {
if (promise == null) {
return;
}
if (FUNC_GET_VALUE.equals(functionName)) {
promise.resolve(textInput.jsGetValue());
} else if (FUNC_IS_FOCUSED.equals(functionName)) {
promise.resolve(textInput.jsIsFocused());
}
}

Expand Down

0 comments on commit fea9add

Please sign in to comment.