react-native-navigation的迁移库

Element.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.reactnativenavigation.views.element;
  2. import android.content.Context;
  3. import android.graphics.Rect;
  4. import androidx.annotation.Keep;
  5. import androidx.annotation.NonNull;
  6. import androidx.annotation.Nullable;
  7. import android.text.SpannableString;
  8. import android.text.SpannedString;
  9. import android.view.View;
  10. import android.widget.FrameLayout;
  11. import android.widget.TextView;
  12. import com.facebook.drawee.drawable.ScalingUtils;
  13. import com.facebook.drawee.generic.GenericDraweeHierarchy;
  14. import com.facebook.drawee.view.DraweeView;
  15. import com.facebook.react.views.view.ReactViewBackgroundDrawable;
  16. import com.reactnativenavigation.utils.TextViewUtils;
  17. import com.reactnativenavigation.utils.UiUtils;
  18. import static com.reactnativenavigation.utils.ColorUtils.labToColor;
  19. import static com.reactnativenavigation.utils.TextViewUtils.setColor;
  20. public class Element extends FrameLayout {
  21. private String elementId;
  22. @Nullable private SpannableString spannableText;
  23. private float originalTextSize;
  24. public Element(@NonNull Context context) {
  25. super(context);
  26. }
  27. public String getElementId() {
  28. return elementId;
  29. }
  30. public void setElementId(String elementId) {
  31. this.elementId = elementId;
  32. }
  33. public View getChild() {
  34. return getChildAt(0);
  35. }
  36. @Override
  37. public void onViewAdded(View child) {
  38. super.onViewAdded(child);
  39. UiUtils.runOnPreDrawOnce(child, () -> {
  40. if (child instanceof TextView) {
  41. SpannedString spannedText = new SpannedString(((TextView) child).getText());
  42. spannableText = new SpannableString(spannedText);
  43. ((TextView) child).setText(spannableText);
  44. originalTextSize = TextViewUtils.getTextSize((TextView) child);
  45. }
  46. });
  47. }
  48. @Keep
  49. public void setClipBounds(Rect clipBounds) {
  50. getChild().setClipBounds(clipBounds);
  51. }
  52. @Keep
  53. public void setMatrixTransform(float value) {
  54. GenericDraweeHierarchy hierarchy = ((DraweeView<GenericDraweeHierarchy>) getChild()).getHierarchy();
  55. if (hierarchy.getActualImageScaleType() != null) {
  56. ((ScalingUtils.InterpolatingScaleType) hierarchy.getActualImageScaleType()).setValue(value);
  57. getChild().invalidate();
  58. }
  59. }
  60. @Keep
  61. public void setBackgroundColor(double[] color) {
  62. ((ReactViewBackgroundDrawable) getChild().getBackground()).setColor(labToColor(color));
  63. }
  64. @Keep
  65. public void setTextColor(double[] color) {
  66. if (spannableText != null) {
  67. setColor(spannableText, labToColor(color));
  68. ((TextView) getChild()).setText(spannableText);
  69. }
  70. }
  71. }