Skip to content

Commit

Permalink
Android works
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw committed Dec 1, 2023
1 parent f5fb619 commit 0abec5a
Show file tree
Hide file tree
Showing 10 changed files with 14,245 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@
import androidx.annotation.Nullable;

import android.content.Context;
import android.graphics.Typeface;
import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextWatcher;
import android.text.style.StyleSpan;
import android.util.AttributeSet;

import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import com.facebook.react.views.textinput.ReactEditText;

public class MarkdownTextInputView extends View {

Expand All @@ -21,4 +31,67 @@ public MarkdownTextInputView(Context context, @Nullable AttributeSet attrs, int
super(context, attrs, defStyleAttr);
}

private ReactEditText mReactEditText;

private TextWatcher mTextWatcher;

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();

View previousSibling = null;
final ViewParent parent = this.getParent();
if (parent instanceof ViewGroup) {
final ViewGroup viewGroup = (ViewGroup) parent;
for (int i = 1; i < viewGroup.getChildCount(); i++) {
if (viewGroup.getChildAt(i) == this) {
previousSibling = viewGroup.getChildAt(i - 1);
break;
}
}
}
if (previousSibling instanceof ReactEditText) {
mReactEditText = (ReactEditText) previousSibling;
mTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

private boolean mIsFormatting = false;

@Override
public void afterTextChanged(Editable editable) {
if (!mIsFormatting) {
mIsFormatting = true;
if (editable instanceof SpannableStringBuilder) {
SpannableStringBuilder ssb = (SpannableStringBuilder) editable;
int selectionStart = mReactEditText.getSelectionStart();
int selectionEnd = mReactEditText.getSelectionEnd();
String text = ssb.toString();
int length = text.length();
ssb.clear();
ssb.append(text);
mReactEditText.setSelection(Math.min(selectionStart, length), Math.min(selectionEnd, length));
int flag = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
ssb.setSpan(new StyleSpan(Typeface.BOLD), 0, Math.min(3, ssb.length()), flag);
}
mIsFormatting = false;
}
}
};
mReactEditText.addTextChangedListener(mTextWatcher);
}
}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mReactEditText.removeTextChangedListener(mTextWatcher);
}
}
23 changes: 21 additions & 2 deletions example/ios/MarkdownTextInputExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,15 @@
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION,
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -592,12 +593,19 @@
);
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "$(inherited)";
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-DFOLLY_NO_CONFIG",
"-DFOLLY_MOBILE=1",
"-DFOLLY_USE_LIBCPP=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
};
name = Debug;
Expand Down Expand Up @@ -635,9 +643,13 @@
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION,
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -655,12 +667,19 @@
"\"$(inherited)\"",
);
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CFLAGS = "$(inherited)";
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-DFOLLY_NO_CONFIG",
"-DFOLLY_MOBILE=1",
"-DFOLLY_USE_LIBCPP=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Loading

0 comments on commit 0abec5a

Please sign in to comment.