Skip to content

Commit

Permalink
Merge pull request #53 from mzaien/master
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyBurger authored Aug 31, 2024
2 parents 98aa9d8 + 5676968 commit 5835234
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ A fork of React Native's `<Text/>` component that supports Animated Values as te
<th>Animateable Text Version</th>
<th>RN Version</th>
</tr>
<tr>
<td> ^0.13.0</td>
<td> ^0.75.0</td>
</tr>
<tr>
<td> ^0.12.0</td>
<td> ^0.74.0</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
import android.view.Gravity;

import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.common.mapbuffer.MapBuffer;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.module.annotations.ReactModule;
Expand Down Expand Up @@ -44,6 +43,11 @@ public class JBTextViewManager
implements IViewManagerWithChildren {

@VisibleForTesting public static final String REACT_CLASS = "JBAnimatedText";
private static final short TX_STATE_KEY_ATTRIBUTED_STRING = 0;
private static final short TX_STATE_KEY_PARAGRAPH_ATTRIBUTES = 1;
// used for text input
private static final short TX_STATE_KEY_HASH = 2;
private static final short TX_STATE_KEY_MOST_RECENT_EVENT_COUNT = 3;

protected @Nullable ReactTextViewManagerCallback mReactTextViewManagerCallback;

Expand Down Expand Up @@ -95,29 +99,35 @@ public boolean needsCustomLayoutForChildren() {
@Override
public Object updateState(
ReactTextView view, ReactStylesDiffMap props, @Nullable StateWrapper stateWrapper) {
// TODO T55794595: Add support for updating state with null stateWrapper
ReadableNativeMap state = stateWrapper.getStateData();
ReadableMap attributedString = state.getMap("attributedString");
ReadableMap paragraphAttributes = state.getMap("paragraphAttributes");

Spannable spanned =
TextLayoutManager.getOrCreateSpannableForText(
view.getContext(), attributedString, mReactTextViewManagerCallback);
view.setSpanned(spanned);

int textBreakStrategy =
TextAttributeProps.getTextBreakStrategy(paragraphAttributes.getString("textBreakStrategy"));
int currentJustificationMode = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
currentJustificationMode = view.getJustificationMode();
MapBuffer state = stateWrapper.getStateDataMapBuffer();
if (state == null) {
return null;
}
else {
MapBuffer attributedString = state.getMapBuffer(TX_STATE_KEY_ATTRIBUTED_STRING);
MapBuffer paragraphAttributes = state.getMapBuffer(TX_STATE_KEY_PARAGRAPH_ATTRIBUTES);

Spannable spanned =
TextLayoutManager.getOrCreateSpannableForText(
view.getContext(), attributedString, mReactTextViewManagerCallback);
view.setSpanned(spanned);

int textBreakStrategy =
TextAttributeProps.getTextBreakStrategy(
paragraphAttributes.getString(TextLayoutManager.PA_KEY_TEXT_BREAK_STRATEGY));

int currentJustificationMode = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
currentJustificationMode = view.getJustificationMode();
}
return new ReactTextUpdate(
spanned,
state.contains(TX_STATE_KEY_MOST_RECENT_EVENT_COUNT) ? state.getInt(TX_STATE_KEY_MOST_RECENT_EVENT_COUNT) : -1,
false, // TODO add this into local Data
TextAttributeProps.getTextAlignment(props, TextLayoutManager.isRTL(attributedString), Gravity.LEFT),
textBreakStrategy,
TextAttributeProps.getJustificationMode(props, currentJustificationMode));
}
return new ReactTextUpdate(
spanned,
state.hasKey("mostRecentEventCount") ? state.getInt("mostRecentEventCount") : -1,
false, // TODO add this into local Data
TextAttributeProps.getTextAlignment(props, TextLayoutManager.isRTL(attributedString), Gravity.LEFT),
textBreakStrategy,
TextAttributeProps.getJustificationMode(props, currentJustificationMode));
}

@Override
Expand All @@ -130,9 +140,9 @@ public Object updateState(
@Override
public long measure(
Context context,
ReadableMap localData,
ReadableMap props,
ReadableMap state,
MapBuffer localData,
MapBuffer props,
MapBuffer state,
float width,
YogaMeasureMode widthMode,
float height,
Expand Down

0 comments on commit 5835234

Please sign in to comment.