Minor changes

This commit is contained in:
Nicolas Gallagher
2016-12-30 22:19:51 -08:00
parent 877c0d2818
commit 351c0ac3d4
5 changed files with 21 additions and 70 deletions
@@ -129,7 +129,7 @@ const examples = [
render() {
return (
<View style={[styles.horizontal, styles.centering]}>
<ActivityIndicator size="40" />
<ActivityIndicator size={40} />
<ActivityIndicator
style={{ marginLeft: 20, transform: [ {scale: 1.5} ] }}
size="large"
@@ -307,11 +307,11 @@ var TouchableDisabled = React.createClass({
render: function() {
return (
<View>
<TouchableOpacity disabled={true} style={[styles.row, styles.block]}>
<TouchableOpacity disabled={true} style={[styles.row, styles.block]} onPress={action('TouchableOpacity')}>
<Text style={styles.disabledButton}>Disabled TouchableOpacity</Text>
</TouchableOpacity>
<TouchableOpacity disabled={false} style={[styles.row, styles.block]}>
<TouchableOpacity disabled={false} style={[styles.row, styles.block]} onPress={action('TouchableOpacity')}>
<Text style={styles.button}>Enabled TouchableOpacity</Text>
</TouchableOpacity>
@@ -321,7 +321,7 @@ var TouchableDisabled = React.createClass({
animationVelocity={0}
underlayColor="rgb(210, 230, 255)"
style={[styles.row, styles.block]}
onPress={() => console.log('custom THW text - highlight')}>
onPress={action('TouchableHighlight')}>
<Text style={styles.disabledButton}>
Disabled TouchableHighlight
</Text>
@@ -332,7 +332,7 @@ var TouchableDisabled = React.createClass({
animationVelocity={0}
underlayColor="rgb(210, 230, 255)"
style={[styles.row, styles.block]}
onPress={() => console.log('custom THW text - highlight')}>
onPress={action('TouchableHighlight')}>
<Text style={styles.button}>
Enabled TouchableHighlight
</Text>
@@ -15,7 +15,8 @@ describe('apis/StyleSheet/resolveTransform', () => {
resolveTransform(resolvedStyle, style);
expect(resolvedStyle).toEqual({
transform: 'scaleX(20) translateX(20px) rotate(20deg)' });
transform: 'scaleX(20) translateX(20px) rotate(20deg)'
});
});
test('transformMatrix', () => {
+7 -61
View File
@@ -6,33 +6,9 @@
* @flow
*/
import { Component } from 'react';
import findNodeHandle from '../findNodeHandle';
import UIManager from '../../apis/UIManager';
type MeasureInWindowOnSuccessCallback = (
x: number,
y: number,
width: number,
height: number,
) => void
type MeasureLayoutOnSuccessCallback = (
left: number,
top: number,
width: number,
height: number
) => void
type MeasureOnSuccessCallback = (
x: number,
y: number,
width: number,
height: number,
pageX: number,
pageY: number
) => void
const NativeMethodsMixin = {
/**
* Removes focus from an input or view. This is the opposite of `focus()`.
@@ -52,11 +28,8 @@ const NativeMethodsMixin = {
/**
* Determines the position and dimensions of the view
*/
measure(callback: MeasureOnSuccessCallback) {
UIManager.measure(
findNodeHandle(this),
mountSafeCallback(this, callback)
);
measure(callback) {
UIManager.measure(findNodeHandle(this), callback);
},
/**
@@ -74,50 +47,23 @@ const NativeMethodsMixin = {
* Note that these measurements are not available until after the rendering
* has been completed in native.
*/
measureInWindow(callback: MeasureInWindowOnSuccessCallback) {
UIManager.measureInWindow(
findNodeHandle(this),
mountSafeCallback(this, callback)
);
measureInWindow(callback) {
UIManager.measureInWindow(findNodeHandle(this), callback);
},
/**
* Measures the view relative to another view (usually an ancestor)
*/
measureLayout(
relativeToNativeNode: Object,
onSuccess: MeasureLayoutOnSuccessCallback,
onFail: () => void /* currently unused */
) {
UIManager.measureLayout(
findNodeHandle(this),
relativeToNativeNode,
mountSafeCallback(this, onFail),
mountSafeCallback(this, onSuccess)
);
measureLayout(relativeToNativeNode, onSuccess, onFail) {
UIManager.measureLayout(findNodeHandle(this), relativeToNativeNode, onFail, onSuccess);
},
/**
* This function sends props straight to the underlying DOM node.
*/
setNativeProps(nativeProps: Object) {
UIManager.updateView(
findNodeHandle(this),
nativeProps,
this
);
UIManager.updateView(findNodeHandle(this), nativeProps, this);
}
};
/**
* In the future, we should cleanup callbacks by cancelling them instead of
* using this.
*/
const mountSafeCallback = (context: Component, callback: ?Function) => (...args) => {
if (!callback) {
return undefined;
}
return callback.apply(context, args);
};
module.exports = NativeMethodsMixin;
+7 -3
View File
@@ -14,15 +14,19 @@
const emptyObject = {};
const objects = {};
const prefix = 'r';
let uniqueID = 1;
const createKey = (id) => `${prefix}${id}`;
class ReactNativePropRegistry {
static register(object: Object): number {
let id = ++uniqueID;
if (process.env.NODE_ENV !== 'production') {
Object.freeze(object);
}
objects[`${id}`] = object;
const key = createKey(id);
objects[key] = object;
return id;
}
@@ -32,8 +36,8 @@ class ReactNativePropRegistry {
// we want it to be a no-op when the value is false or null
return emptyObject;
}
const object = objects[`${id}`];
const key = createKey(id);
const object = objects[key];
if (!object) {
console.warn('Invalid style with id `' + id + '`. Skipping ...');
return emptyObject;