Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add starting zoomScale #39

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions android/src/main/java/com/rnds/DirectedScrollView.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class DirectedScrollView extends ReactViewGroup {

private float minimumZoomScale = 1.0f;
private float maximumZoomScale = 1.0f;
private float zoomScale = 1.0f;
private boolean bounces = true;
private boolean alwaysBounceVertical = false;
private boolean alwaysBounceHorizontal = false;
Expand Down Expand Up @@ -336,6 +337,8 @@ private void anchorChildren() {
for (DirectedScrollViewChild scrollableChild : scrollableChildren) {
scrollableChild.setPivotY(0);
scrollableChild.setPivotX(0);
scrollableChild.setScaleX(zoomScale);
scrollableChild.setScaleY(zoomScale);
}
}

Expand Down Expand Up @@ -410,6 +413,10 @@ private void emitScrollEvent(
getHeight()));
}

public void setZoomScale(final float zoomScale) {
this.zoomScale = zoomScale;
}

public void setMaximumZoomScale(final float maximumZoomScale) {
this.maximumZoomScale = maximumZoomScale;
}
Expand Down
5 changes: 5 additions & 0 deletions android/src/main/java/com/rnds/DirectedScrollViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public static Map createExportedCustomDirectEventTypeConstants() {
.build();
}

@ReactProp(name = "zoomScale", defaultFloat = 1.0f)
public void setZoomScale(DirectedScrollView view, @Nullable float zoomScale) {
view.setZoomScale(zoomScale);
}

@ReactProp(name = "minimumZoomScale", defaultFloat = 1.0f)
public void setMinimumZoomScale(DirectedScrollView view, @Nullable float minimumZoomScale) {
view.setMinimumZoomScale(minimumZoomScale);
Expand Down
33 changes: 19 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React, { Component } from 'react';
import ReactNative, { requireNativeComponent, View, UIManager, StyleSheet, Platform } from 'react-native';
import ReactNative, {
requireNativeComponent,
View,
UIManager,
StyleSheet,
Platform,
} from 'react-native';
import ScrollResponder from 'react-native/Libraries/Components/ScrollResponder';
import createReactClass from 'create-react-class';

Expand All @@ -21,17 +27,17 @@ const ScrollView = createReactClass({
return ReactNative.findNodeHandle(this._scrollViewRef);
},
scrollTo: function({ x, y, animated }) {
UIManager.dispatchViewManagerCommand(
UIManager.dispatchViewManagerCommand(
this.getScrollableNode(),
UIManager.DirectedScrollView.Commands.scrollTo,
[x || 0, y || 0, animated !== false],
);
},
zoomToStart: function({ animated }) {
UIManager.dispatchViewManagerCommand(
zoomToStart: function({ animated, zoomScale }) {
UIManager.dispatchViewManagerCommand(
this.getScrollableNode(),
UIManager.DirectedScrollView.Commands.zoomToStart,
[animated !== false],
[animated !== false, zoomScale],
);
},
_scrollViewRef: null,
Expand All @@ -40,12 +46,15 @@ const ScrollView = createReactClass({
},
componentDidMount: function() {
setTimeout(() => {
this.zoomToStart({animated: false});
this.zoomToStart({
animated: false,
zoomScale: this.props.zoomScale ? this.props.zoomScale : 1.0,
});
}, 0);
},
render: function() {
return (
<NativeScrollView
<NativeScrollView
{...this.props}
ref={this._setScrollViewRef}
onScrollBeginDrag={this.scrollResponderHandleScrollBeginDrag}
Expand All @@ -66,19 +75,15 @@ const ScrollView = createReactClass({
</View>
</NativeScrollView>
);
}
},
});

export default ScrollView;

export const ScrollViewChild = createReactClass({
render: function() {
return (
<NativeScrollViewChild {...this.props}>
{this.props.children}
</NativeScrollViewChild>
);
}
return <NativeScrollViewChild {...this.props}>{this.props.children}</NativeScrollViewChild>;
},
});

export const scrollViewWillBeginDragging = 'scrollViewWillBeginDragging';
Expand Down
7 changes: 4 additions & 3 deletions ios/RCTDirectedScrollView/DirectedScrollViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ -(void)scrollViewDidEndDragging {
RCT_EXPORT_VIEW_PROPERTY(alwaysBounceHorizontal, BOOL)
RCT_EXPORT_VIEW_PROPERTY(alwaysBounceVertical, BOOL)
RCT_EXPORT_VIEW_PROPERTY(bouncesZoom, BOOL)
RCT_EXPORT_VIEW_PROPERTY(zoomScale, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(maximumZoomScale, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(minimumZoomScale, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL)
Expand All @@ -114,7 +115,7 @@ -(void)scrollViewDidEndDragging {
RCT_EXPORT_VIEW_PROPERTY(decelerationRate, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(directionalLockEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL)
RCT_REMAP_VIEW_PROPERTY(pinchGestureEnabled, scrollView.pinchGestureEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(pinchGestureEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
RCT_EXPORT_VIEW_PROPERTY(scrollIndicatorInsets, UIEdgeInsets)
RCT_EXPORT_VIEW_PROPERTY(snapToInterval, int)
Expand Down Expand Up @@ -145,14 +146,14 @@ -(void)scrollViewDidEndDragging {
}

RCT_EXPORT_METHOD(zoomToStart:(nonnull NSNumber *)reactTag
animated:(BOOL)animated)
animated:(BOOL)animated zoomScale:(CGFloat)zoomScale)
{
[self.bridge.uiManager addUIBlock:
^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
UIView *view = viewRegistry[reactTag];
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
[(id<RCTScrollableProtocol>)view zoomToRect:CGRectMake(0, 0, 0, 0) animated:animated];
[((RCTScrollView*)view).scrollView setZoomScale:1.0 animated:animated];
[((RCTScrollView*)view).scrollView setZoomScale:zoomScale animated:animated];
} else {
RCTLogError(@"tried to zoomToRect: on non-RCTScrollableProtocol view %@ with tag #%@", view, reactTag);
}
Expand Down