Skip to content

Commit

Permalink
Merge branch 'master' into animated-super
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Mar 20, 2017
2 parents 6d1de4e + b53d76e commit b01fe77
Show file tree
Hide file tree
Showing 64 changed files with 1,048 additions and 532 deletions.
39 changes: 9 additions & 30 deletions Examples/UIExplorer/js/TextInputExample.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,34 +103,6 @@ class TextEventsExample extends React.Component {
}
}

class AutoExpandingTextInput extends React.Component {
state: any;

constructor(props) {
super(props);
this.state = {
text: 'React Native enables you to build world-class application experiences on native platforms using a consistent developer experience based on JavaScript and React. The focus of React Native is on developer efficiency across all the platforms you care about — learn once, write anywhere. Facebook uses React Native in multiple production apps and will continue investing in React Native.',
height: 0,
};
}
render() {
return (
<TextInput
{...this.props}
multiline={true}
onChangeText={(text) => {
this.setState({text});
}}
onContentSizeChange={(event) => {
this.setState({height: event.nativeEvent.contentSize.height});
}}
style={[styles.default, {height: Math.max(35, this.state.height)}]}
value={this.state.text}
/>
);
}
}

class RewriteExample extends React.Component {
state: any;

Expand Down Expand Up @@ -403,6 +375,10 @@ var styles = StyleSheet.create({
padding: 4,
marginBottom: 4,
},
multilineExpandable: {
height: 'auto',
maxHeight: 100,
},
multilineWithFontStyles: {
color: 'blue',
fontWeight: 'bold',
Expand Down Expand Up @@ -801,10 +777,13 @@ exports.examples = [
render: function() {
return (
<View>
<AutoExpandingTextInput
<TextInput
placeholder="height increases with content"
defaultValue="React Native enables you to build world-class application experiences on native platforms using a consistent developer experience based on JavaScript and React. The focus of React Native is on developer efficiency across all the platforms you care about - learn once, write anywhere. Facebook uses React Native in multiple production apps and will continue investing in React Native."
multiline={true}
enablesReturnKeyAutomatically={true}
returnKeyType="default"
returnKeyType="go"
style={[styles.multiline, styles.multilineExpandable]}
/>
</View>
);
Expand Down
74 changes: 35 additions & 39 deletions Libraries/Animated/src/AnimatedImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1513,9 +1513,9 @@ class AnimatedStyle extends AnimatedWithChildren {

// Recursively get values for nested styles (like iOS's shadowOffset)
__walkStyleAndGetValues(style) {
let updatedStyle = {};
for (let key in style) {
let value = style[key];
const updatedStyle = {};
for (const key in style) {
const value = style[key];
if (value instanceof Animated) {
if (!value.__isNative) {
// We cannot use value of natively driven nodes this way as the value we have access from
Expand All @@ -1538,9 +1538,9 @@ class AnimatedStyle extends AnimatedWithChildren {

// Recursively get animated values for nested styles (like iOS's shadowOffset)
__walkStyleAndGetAnimatedValues(style) {
let updatedStyle = {};
for (let key in style) {
let value = style[key];
const updatedStyle = {};
for (const key in style) {
const value = style[key];
if (value instanceof Animated) {
updatedStyle[key] = value.__getAnimatedValue();
} else if (value && !Array.isArray(value) && typeof value === 'object') {
Expand Down Expand Up @@ -1694,7 +1694,9 @@ class AnimatedProps extends Animated {
}

setNativeView(animatedView: any): void {
invariant(this._animatedView === undefined, 'Animated view already set.');
if (this._animatedView === animatedView) {
return;
}
this._animatedView = animatedView;
if (this.__isNative) {
this.__connectAnimatedView();
Expand Down Expand Up @@ -1733,7 +1735,9 @@ class AnimatedProps extends Animated {
function createAnimatedComponent(Component: any): any {
class AnimatedComponent extends React.Component {
_component: any;
_prevComponent: any;
_propsAnimated: AnimatedProps;
_eventDetachers: Array<Function> = [];
_setComponentRef: Function;

constructor(props: Object) {
Expand All @@ -1743,7 +1747,7 @@ function createAnimatedComponent(Component: any): any {

componentWillUnmount() {
this._propsAnimated && this._propsAnimated.__detach();
this._detachNativeEvents(this.props);
this._detachNativeEvents();
}

setNativeProps(props) {
Expand All @@ -1756,42 +1760,28 @@ function createAnimatedComponent(Component: any): any {

componentDidMount() {
this._propsAnimated.setNativeView(this._component);

this._attachNativeEvents(this.props);
this._attachNativeEvents();
}

_attachNativeEvents(newProps) {
if (newProps !== this.props) {
this._detachNativeEvents(this.props);
}

_attachNativeEvents() {
// Make sure to get the scrollable node for components that implement
// `ScrollResponder.Mixin`.
const ref = this._component.getScrollableNode ?
const scrollableNode = this._component.getScrollableNode ?
this._component.getScrollableNode() :
this._component;

for (const key in newProps) {
const prop = newProps[key];
for (const key in this.props) {
const prop = this.props[key];
if (prop instanceof AnimatedEvent && prop.__isNative) {
prop.__attach(ref, key);
prop.__attach(scrollableNode, key);
this._eventDetachers.push(() => prop.__detach(scrollableNode, key));
}
}
}

_detachNativeEvents(props) {
// Make sure to get the scrollable node for components that implement
// `ScrollResponder.Mixin`.
const ref = this._component.getScrollableNode ?
this._component.getScrollableNode() :
this._component;

for (const key in props) {
const prop = props[key];
if (prop instanceof AnimatedEvent && prop.__isNative) {
prop.__detach(ref, key);
}
}
_detachNativeEvents() {
this._eventDetachers.forEach(remove => remove());
this._eventDetachers = [];
}

_attachProps(nextProps) {
Expand Down Expand Up @@ -1824,10 +1814,6 @@ function createAnimatedComponent(Component: any): any {
callback,
);

if (this._component) {
this._propsAnimated.setNativeView(this._component);
}

// When you call detach, it removes the element from the parent list
// of children. If it goes to 0, then the parent also detaches itself
// and so on.
Expand All @@ -1839,9 +1825,18 @@ function createAnimatedComponent(Component: any): any {
oldPropsAnimated && oldPropsAnimated.__detach();
}

componentWillReceiveProps(nextProps) {
this._attachProps(nextProps);
this._attachNativeEvents(nextProps);
componentWillReceiveProps(newProps) {
this._attachProps(newProps);
}

componentDidUpdate(prevProps) {
if (this._component !== this._prevComponent) {
this._propsAnimated.setNativeView(this._component);
}
if (this._component !== this._prevComponent || prevProps !== this.props) {
this._detachNativeEvents();
this._attachNativeEvents();
}
}

render() {
Expand All @@ -1854,6 +1849,7 @@ function createAnimatedComponent(Component: any): any {
}

_setComponentRef(c) {
this._prevComponent = this._component;
this._component = c;
}

Expand Down
7 changes: 7 additions & 0 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ const TextInput = React.createClass({
if (props.inputView) {
children = [children, props.inputView];
}
props.style.unshift(styles.multilineInput);
textContainer =
<RCTTextView
ref={this._setNativeRef}
Expand Down Expand Up @@ -867,6 +868,12 @@ var styles = StyleSheet.create({
input: {
alignSelf: 'stretch',
},
multilineInput: {
// This default top inset makes RCTTextView seem as close as possible
// to single-line RCTTextField defaults, using the system defaults
// of font size 17 and a height of 31 points.
paddingTop: 5,
},
});

module.exports = TextInput;
2 changes: 1 addition & 1 deletion Libraries/CustomComponents/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type OptionalProps<ItemT> = {
*/
keyExtractor: (item: ItemT, index: number) => string,
/**
* Multiple columns can only be rendered with `horizontal={false}`` and will zig-zag like a
* Multiple columns can only be rendered with `horizontal={false}` and will zig-zag like a
* `flexWrap` layout. Items should all be the same height - masonry layouts are not supported.
*/
numColumns: number,
Expand Down
51 changes: 2 additions & 49 deletions Libraries/Image/RCTLocalAssetImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,6 @@ - (BOOL)shouldCacheLoadedImages
return NO;
}

static NSString *bundleName(NSBundle *bundle)
{
NSString *name = bundle.infoDictionary[@"CFBundleName"];
if (!name) {
name = [[bundle.bundlePath lastPathComponent] stringByDeletingPathExtension];
}
return name;
}

static NSBundle *bundleForPath(NSString *key)
{
static NSMutableDictionary *bundleCache;
if (!bundleCache) {
bundleCache = [NSMutableDictionary new];
bundleCache[@"main"] = [NSBundle mainBundle];

// Initialize every bundle in the array
for (NSString *path in [[NSBundle mainBundle] pathsForResourcesOfType:@"bundle" inDirectory:nil]) {
[NSBundle bundleWithPath:path];
}

// The bundles initialized above will now also be in `allBundles`
for (NSBundle *bundle in [NSBundle allBundles]) {
bundleCache[bundleName(bundle)] = bundle;
}
}

return bundleCache[key];
}

- (RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
size:(CGSize)size
scale:(CGFloat)scale
Expand All @@ -80,31 +50,14 @@ - (RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
return;
}

NSString *imageName = RCTBundlePathForURL(imageURL);

NSBundle *bundle;
NSArray *imagePathComponents = [imageName pathComponents];
if ([imagePathComponents count] > 1 &&
[[[imagePathComponents firstObject] pathExtension] isEqualToString:@"bundle"]) {
NSString *bundlePath = [imagePathComponents firstObject];
bundle = bundleForPath([bundlePath stringByDeletingPathExtension]);
imageName = [imageName substringFromIndex:(bundlePath.length + 1)];
}

UIImage *image;
if (bundle) {
image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil];
} else {
image = [UIImage imageNamed:imageName];
}

UIImage *image = RCTImageFromLocalAssetURL(imageURL);
if (image) {
if (progressHandler) {
progressHandler(1, 1);
}
completionHandler(nil, image);
} else {
NSString *message = [NSString stringWithFormat:@"Could not find image named %@", imageName];
NSString *message = [NSString stringWithFormat:@"Could not find image %@", imageURL];
RCTLogWarn(@"%@", message);
completionHandler(RCTErrorWithMessage(message), nil);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ var ReactNativeEventEmitter = {
) {
var nativeEvent = nativeEventParam || EMPTY_NATIVE_EVENT;
var inst = ReactNativeComponentTree.getInstanceFromNode(rootNodeID);
if (!inst) {
// If the original instance is already gone, we don't have to dispatch
// any events.
return;
}
ReactGenericBatching.batchedUpdates(function() {
ReactNativeEventEmitter.handleTopLevel(
topLevelType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
* requiring that the `dispatchMarker` be the same as the dispatched ID.
*/
function accumulateDispatches(inst, ignoredDirection, event) {
if (event && event.dispatchConfig.registrationName) {
if (inst && event && event.dispatchConfig.registrationName) {
var registrationName = event.dispatchConfig.registrationName;
var listener = getListener(inst, registrationName);
if (listener) {
Expand Down
8 changes: 8 additions & 0 deletions Libraries/Text/RCTText.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
58B511D01A9E6C5C00147676 /* RCTShadowText.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511CB1A9E6C5C00147676 /* RCTShadowText.m */; };
58B511D11A9E6C5C00147676 /* RCTTextManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511CD1A9E6C5C00147676 /* RCTTextManager.m */; };
58B512161A9E6EFF00147676 /* RCTText.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B512141A9E6EFF00147676 /* RCTText.m */; };
59B125C91E6E4E15004E2A67 /* RCTUITextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59B125C81E6E4E15004E2A67 /* RCTUITextView.m */; };
59B125CA1E6E4E15004E2A67 /* RCTUITextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59B125C81E6E4E15004E2A67 /* RCTUITextView.m */; };
59F60E911E661BDD0081153B /* RCTShadowTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 59F60E8E1E661BDD0081153B /* RCTShadowTextField.m */; };
59F60E921E661BDD0081153B /* RCTShadowTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 59F60E8E1E661BDD0081153B /* RCTShadowTextField.m */; };
59F60E931E661BDD0081153B /* RCTShadowTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59F60E901E661BDD0081153B /* RCTShadowTextView.m */; };
Expand Down Expand Up @@ -58,6 +60,8 @@
58B511CD1A9E6C5C00147676 /* RCTTextManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTextManager.m; sourceTree = "<group>"; };
58B512141A9E6EFF00147676 /* RCTText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTText.m; sourceTree = "<group>"; };
58B512151A9E6EFF00147676 /* RCTText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTText.h; sourceTree = "<group>"; };
59B125C71E6E4E15004E2A67 /* RCTUITextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTUITextView.h; sourceTree = "<group>"; };
59B125C81E6E4E15004E2A67 /* RCTUITextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUITextView.m; sourceTree = "<group>"; };
59F60E8D1E661BDD0081153B /* RCTShadowTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTShadowTextField.h; sourceTree = "<group>"; };
59F60E8E1E661BDD0081153B /* RCTShadowTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTShadowTextField.m; sourceTree = "<group>"; };
59F60E8F1E661BDD0081153B /* RCTShadowTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTShadowTextView.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -97,6 +101,8 @@
131B6ABD1AF0CD0600FFC3E0 /* RCTTextView.m */,
131B6ABE1AF0CD0600FFC3E0 /* RCTTextViewManager.h */,
131B6ABF1AF0CD0600FFC3E0 /* RCTTextViewManager.m */,
59B125C71E6E4E15004E2A67 /* RCTUITextView.h */,
59B125C81E6E4E15004E2A67 /* RCTUITextView.m */,
);
indentWidth = 2;
sourceTree = "<group>";
Expand Down Expand Up @@ -194,6 +200,7 @@
2D3B5F341D9B103100451313 /* RCTRawTextManager.m in Sources */,
59F60E921E661BDD0081153B /* RCTShadowTextField.m in Sources */,
AF3225FA1DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */,
59B125CA1E6E4E15004E2A67 /* RCTUITextView.m in Sources */,
2D3B5F3C1D9B106F00451313 /* RCTTextViewManager.m in Sources */,
59F60E941E661BDD0081153B /* RCTShadowTextView.m in Sources */,
2D3B5F331D9B102D00451313 /* RCTTextSelection.m in Sources */,
Expand All @@ -214,6 +221,7 @@
1362F1011B4D51F400E06D8C /* RCTTextFieldManager.m in Sources */,
59F60E911E661BDD0081153B /* RCTShadowTextField.m in Sources */,
AF3225F91DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */,
59B125C91E6E4E15004E2A67 /* RCTUITextView.m in Sources */,
131B6AC11AF0CD0600FFC3E0 /* RCTTextViewManager.m in Sources */,
59F60E931E661BDD0081153B /* RCTShadowTextView.m in Sources */,
58B511CF1A9E6C5C00147676 /* RCTShadowRawText.m in Sources */,
Expand Down
Loading

0 comments on commit b01fe77

Please sign in to comment.