forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcb4eb0
commit aac94a8
Showing
6 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import android.text.TextUtils; | ||
import android.view.View; | ||
import android.view.ViewParent; | ||
import android.view.ViewTreeObserver; | ||
import android.view.accessibility.AccessibilityEvent; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
@@ -30,6 +31,8 @@ | |
import com.facebook.react.uimanager.annotations.ReactProp; | ||
import com.facebook.react.uimanager.events.PointerEventHelper; | ||
import com.facebook.react.uimanager.util.ReactFindViewUtil; | ||
import com.facebook.react.views.view.ReactViewGroup; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
@@ -40,7 +43,32 @@ | |
* provides support for base view properties such as backgroundColor, opacity, etc. | ||
*/ | ||
public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode> | ||
extends ViewManager<T, C> implements BaseViewManagerInterface<T> { | ||
extends ViewManager<T, C> implements BaseViewManagerInterface<T>, View.OnLayoutChangeListener { | ||
|
||
View.OnLayoutChangeListener layoutListener = null; | ||
String transformOrigin = null; | ||
|
||
@Override | ||
public void onLayoutChange(View v, | ||
int left, | ||
int top, | ||
int right, | ||
int bottom, | ||
int oldLeft, | ||
int oldTop, | ||
int oldRight, | ||
int oldBottom) { | ||
// Old width and height | ||
int oldWidth = oldRight - oldLeft; | ||
int oldHeight = oldBottom - oldTop; | ||
|
||
// Current width and height | ||
int currentWidth = right - left; | ||
int currentHeight = bottom - top; | ||
if (currentHeight != oldHeight || currentWidth != oldWidth) { | ||
setTransformOriginWithViewHeightAndWidth((T) v, currentWidth, currentHeight); | ||
} | ||
} | ||
|
||
private static final int PERSPECTIVE_ARRAY_INVERTED_CAMERA_DISTANCE_INDEX = 2; | ||
private static final float CAMERA_DISTANCE_NORMALIZATION_MULTIPLIER = (float) Math.sqrt(5); | ||
|
@@ -126,6 +154,8 @@ protected T prepareToRecycleView(@NonNull ThemedReactContext reactContext, T vie | |
// Other stuff | ||
view.setForeground(null); | ||
|
||
view.removeOnLayoutChangeListener(this); | ||
|
||
return view; | ||
} | ||
|
||
|
@@ -148,6 +178,44 @@ public void setTransform(@NonNull T view, @Nullable ReadableArray matrix) { | |
} | ||
} | ||
|
||
private void setTransformOriginWithViewHeightAndWidth(T view, float width, float height) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
intergalacticspacehighway
Author
Owner
|
||
if (transformOrigin == null) { | ||
transformOrigin = "0 0"; | ||
} | ||
|
||
float[] pivotPoints = new float[2]; | ||
// Split the string by space | ||
String[] parts = transformOrigin.split(" "); | ||
|
||
for (int i = 0; i < parts.length; i++) { | ||
boolean isPercent = parts[i].contains("%"); | ||
float value = Float.parseFloat(parts[i].replace("%", "")); | ||
This comment has been minimized.
Sorry, something went wrong.
jacobp100
Collaborator
|
||
if (isPercent) { | ||
value = (i == 0 ? width : height) * value / 100.0f; | ||
pivotPoints[i] = value; | ||
} else { | ||
pivotPoints[i] = PixelUtil.toPixelFromDIP(value); | ||
} | ||
} | ||
|
||
view.setPivotX(pivotPoints[0]); | ||
view.setPivotY(pivotPoints[1]); | ||
|
||
|
||
view.setRotation(view.getRotation()); | ||
view.setScaleX(view.getScaleX()); | ||
view.setScaleY(view.getScaleX()); | ||
} | ||
|
||
@Override | ||
@ReactProp(name = ViewProps.TRANSFORM_ORIGIN) | ||
public void setTransformOrigin(@NonNull T view, @Nullable String transformOrigin) { | ||
this.transformOrigin = transformOrigin; | ||
// we need to recalculate rotation/scale based new dimensions. Attaches same listener, so looks fine. | ||
view.addOnLayoutChangeListener(this); | ||
setTransformOriginWithViewHeightAndWidth(view, view.getWidth(), view.getHeight()); | ||
} | ||
|
||
@Override | ||
@ReactProp(name = ViewProps.OPACITY, defaultFloat = 1.f) | ||
public void setOpacity(@NonNull T view, float opacity) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Todo: exception handling