[react-native] Reformat all files using prettier.

prettier --parser typescript --tab-width 4 --semi --trailing-comma es5 \
             --write --print-width 120 \
             types/react-native{,/test}/*.ts*
This commit is contained in:
Eloy Durán
2017-11-15 14:52:03 +01:00
parent d7b5cd9707
commit 368972eb26
4 changed files with 2046 additions and 2163 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,94 +1,80 @@
import * as React from 'react-native'
import * as React from "react-native";
import {
Animated,
View,
} from 'react-native';
import { Animated, View } from "react-native";
function TestAnimatedAPI() {
// Value
const v1 = new Animated.Value(0);
const v2 = new Animated.Value(0);
// Value
const v1 = new Animated.Value(0);
const v2 = new Animated.Value(0);
v1.setValue(0.1);
v1.setValue(0.1);
v1.addListener(e => {
const n: number = e.value;
});
v1.addListener(e => {
const n: number = e.value;
});
const v200 = v1.interpolate({
inputRange: [0, 1],
outputRange: [0, 200],
});
const v200 = v1.interpolate({
inputRange: [0, 1],
outputRange: [0, 200],
});
// ValueXY
const position = new Animated.ValueXY({ x: 0, y: 0 });
// ValueXY
const position = new Animated.ValueXY({ x: 0, y: 0 });
// Animation functions
const spring1 = Animated.spring(v1, {
toValue: 0.5,
tension: 10,
});
// Animation functions
const spring1 = Animated.spring(v1, {
toValue: 0.5,
tension: 10,
});
const springXY = Animated.spring(position, {
toValue: {
x: 1,
y: 2,
}
});
const springXY = Animated.spring(position, {
toValue: {
x: 1,
y: 2,
},
});
spring1.start();
spring1.stop();
spring1.start();
spring1.stop();
Animated.parallel([
Animated.spring(v1, { toValue: 1 }),
Animated.spring(v2, { toValue: 1 }),
], {
stopTogether: true,
});
Animated.parallel([Animated.spring(v1, { toValue: 1 }), Animated.spring(v2, { toValue: 1 })], {
stopTogether: true,
});
Animated.decay(v1, {
velocity: 2,
});
Animated.decay(v1, {
velocity: 2,
});
Animated.timing(v1, {
toValue: 1,
duration: 100,
delay: 100,
easing: v => v,
});
Animated.timing(v1, {
toValue: 1,
duration: 100,
delay: 100,
easing: v => v,
});
Animated.add(v1, v2);
Animated.divide(v1, v2);
Animated.multiply(v1, v2);
Animated.modulo(v1, 2);
Animated.add(v1, v2);
Animated.divide(v1, v2);
Animated.multiply(v1, v2);
Animated.modulo(v1, 2);
Animated.delay(100);
Animated.delay(100);
Animated.sequence([
spring1,
springXY,
]);
Animated.sequence([spring1, springXY]);
Animated.stagger(100, [
spring1,
springXY,
]);
Animated.stagger(100, [spring1, springXY]);
return (
<View>
<Animated.View
style={[
position.getLayout(),
{
opacity: v1,
}]}>
</Animated.View>
return (
<View>
<Animated.View
style={[
position.getLayout(),
{
opacity: v1,
},
]}
/>
<Animated.Image
style={position.getTranslateTransform()}
>
</Animated.Image>
</View>
);
<Animated.Image style={position.getTranslateTransform()} />
</View>
);
}

View File

@@ -11,7 +11,7 @@ The content of index.io.js could be something like
For a list of complete Typescript examples: check https://github.com/bgrieder/RNTSExplorer
*/
import * as React from 'react'
import * as React from "react";
import {
Alert,
AppState,
@@ -43,15 +43,15 @@ import {
TabBarIOS,
NativeModules,
MaskedView,
} from 'react-native';
} from "react-native";
declare module 'react-native' {
declare module "react-native" {
interface NativeTypedModule {
someFunction(): void;
someProperty: string;
}
interface NativeModulesStatic {
NativeTypedModule: NativeTypedModule
NativeTypedModule: NativeTypedModule;
}
}
@@ -61,16 +61,10 @@ NativeModules.NativeTypedModule.someFunction();
NativeModules.NativeTypedModule.someProperty = "";
function testDimensions() {
const {
width,
height,
scale,
fontScale,
} = Dimensions.get(1 === 1 ? "window" : "screen");
const { width, height, scale, fontScale } = Dimensions.get(1 === 1 ? "window" : "screen");
}
BackAndroid.addEventListener("hardwareBackPress", () => {
});
BackAndroid.addEventListener("hardwareBackPress", () => {});
interface LocalStyles {
container: ViewStyle;
@@ -78,80 +72,69 @@ interface LocalStyles {
instructions: TextStyle;
}
const styles = StyleSheet.create<LocalStyles>(
{
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
}
)
const styles = StyleSheet.create<LocalStyles>({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF",
},
welcome: {
fontSize: 20,
textAlign: "center",
margin: 10,
},
instructions: {
textAlign: "center",
color: "#333333",
marginBottom: 5,
},
});
//alternative declaration of styles (inline typings)
const stylesAlt = StyleSheet.create(
{
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
}
}
);
const stylesAlt = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF",
},
welcome: {
fontSize: 20,
textAlign: "center",
margin: 10,
},
instructions: {
textAlign: "center",
color: "#333333",
marginBottom: 5,
},
});
const welcomeFontSize = StyleSheet.flatten(styles.welcome).fontSize
const welcomeFontSize = StyleSheet.flatten(styles.welcome).fontSize;
class CustomView extends React.Component {
render() {
return (
<Text style={[StyleSheet.absoluteFill, {...StyleSheet.absoluteFillObject}]}>Custom View</Text>
);
return <Text style={[StyleSheet.absoluteFill, { ...StyleSheet.absoluteFillObject }]}>Custom View</Text>;
}
}
class Welcome extends React.Component {
refs: {
[key: string]: any
rootView: View
customView: CustomView
}
[key: string]: any;
rootView: View;
customView: CustomView;
};
testNativeMethods() {
// this.setNativeProps({});
const { rootView } = this.refs;
rootView.measure((x: number, y: number, width: number, height: number) => {
});
rootView.measure((x: number, y: number, width: number, height: number) => {});
}
testFindNodeHandle() {
const { rootView, customView } = this.refs;
const nativeComponentHandle = findNodeHandle(rootView);
@@ -159,25 +142,20 @@ class Welcome extends React.Component {
const customComponentHandle = findNodeHandle(customView);
const fromHandle = findNodeHandle(customComponentHandle);
}
render() {
return (
<View ref="rootView" style={[[styles.container], undefined, null, false]}>
<Text style={styles.welcome}>
Welcome to React Native
</Text>
<Text style={styles.welcome}>Welcome to React Native</Text>
<Text style={styles.instructions}>To get started, edit index.ios.js</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Press Cmd+R to reload,{"\n"}
Cmd+D or shake for dev menu
</Text>
<CustomView ref="customView" />
</View>
)
);
}
}
@@ -186,17 +164,17 @@ export default Welcome;
// App State
function appStateListener(state: string) {
console.log('New state: ' + state);
console.log("New state: " + state);
}
function appStateTest() {
console.log('Current state: ' + AppState.currentState);
AppState.addEventListener('change', appStateListener);
console.log("Current state: " + AppState.currentState);
AppState.addEventListener("change", appStateListener);
}
function appStateIOSTest() {
console.log('Current state: ' + AppStateIOS.currentState);
AppStateIOS.addEventListener('change', appStateListener);
console.log("Current state: " + AppStateIOS.currentState);
AppStateIOS.addEventListener("change", appStateListener);
}
// ViewPagerAndroid
@@ -204,27 +182,28 @@ function appStateIOSTest() {
export class ViewPagerAndroidTest {
render() {
return (
<ViewPagerAndroid style={{height: 56}}
<ViewPagerAndroid
style={{ height: 56 }}
initialPage={0}
keyboardDismissMode={'on-drag'}
onPageScroll={(e) => {
keyboardDismissMode={"on-drag"}
onPageScroll={e => {
console.log(`position: ${e.nativeEvent.position}`);
console.log(`offset: ${e.nativeEvent.offset}`);
}}
onPageSelected={(e) => {
console.log(`position: ${e.nativeEvent.position}`)
onPageSelected={e => {
console.log(`position: ${e.nativeEvent.position}`);
}}
/>
/>
);
}
}
const profiledJSONParse = Systrace.measure('JSON', 'parse', JSON.parse)
profiledJSONParse('[]')
const profiledJSONParse = Systrace.measure("JSON", "parse", JSON.parse);
profiledJSONParse("[]");
InteractionManager.runAfterInteractions(() => {
// ...
}).then(() => 'done')
}).then(() => "done");
export class FlatListTest extends React.Component<FlatListProperties<number>, {}> {
_renderItem = (rowData: any) => {
@@ -233,9 +212,9 @@ export class FlatListTest extends React.Component<FlatListProperties<number>, {}
<Text> {rowData.item} </Text>
</View>
);
}
};
_renderSeparator= () => <View style={{height: 1, width: '100%', backgroundColor: 'gray'}} />
_renderSeparator = () => <View style={{ height: 1, width: "100%", backgroundColor: "gray" }} />;
render() {
return (
@@ -250,20 +229,35 @@ export class FlatListTest extends React.Component<FlatListProperties<number>, {}
export class SectionListTest extends React.Component<SectionListProperties<string>, {}> {
render() {
const sections = [{
title: 'Section 1',
data: ['A', 'B', 'C', 'D', 'E'],
}, {
title: 'Section 2',
data: ['A2', 'B2', 'C2', 'D2', 'E2'],
renderItem: (info: { item: string }) => <View><Text>{info.item}</Text></View>
}];
const sections = [
{
title: "Section 1",
data: ["A", "B", "C", "D", "E"],
},
{
title: "Section 2",
data: ["A2", "B2", "C2", "D2", "E2"],
renderItem: (info: { item: string }) => (
<View>
<Text>{info.item}</Text>
</View>
),
},
];
return (
<SectionList
sections={sections}
renderSectionHeader={({section}) => <View><Text>{section.title}</Text></View>}
renderItem={(info: { item: string }) => <View><Text>{info.item}</Text></View>}
renderSectionHeader={({ section }) => (
<View>
<Text>{section.title}</Text>
</View>
)}
renderItem={(info: { item: string }) => (
<View>
<Text>{info.item}</Text>
</View>
)}
/>
);
}
@@ -271,43 +265,39 @@ export class SectionListTest extends React.Component<SectionListProperties<strin
export class CapsLockComponent extends React.Component<TextProperties> {
render() {
const content = (this.props.children || "") as string
return (
<Text {...this.props} >
{content.toUpperCase()}
</Text>
)
const content = (this.props.children || "") as string;
return <Text {...this.props}>{content.toUpperCase()}</Text>;
}
}
class ScrollerListComponentTest extends React.Component<{}, { dataSource: ListViewDataSource}> {
class ScrollerListComponentTest extends React.Component<{}, { dataSource: ListViewDataSource }> {
render() {
const scrollViewStyle1 = StyleSheet.create({
scrollView: {
backgroundColor: 'red',
backgroundColor: "red",
},
});
const scrollViewStyle2 = {
flex: 1
flex: 1,
};
return (
<ListView dataSource={this.state.dataSource}
renderScrollComponent={(props) => {
<ListView
dataSource={this.state.dataSource}
renderScrollComponent={props => {
if (props.scrollEnabled) {
throw new Error("Expected scroll to be enabled.")
throw new Error("Expected scroll to be enabled.");
}
return <ScrollView {...props} style={[scrollViewStyle1.scrollView, scrollViewStyle2]}/>
return <ScrollView {...props} style={[scrollViewStyle1.scrollView, scrollViewStyle2]} />;
}}
renderRow={({ type, data }, _, row) => {
return <Text>Filler</Text>
}
} />
)
return <Text>Filler</Text>;
}}
/>
);
}
}
class TabBarTest extends React.Component {
render() {
return (
@@ -315,20 +305,21 @@ class TabBarTest extends React.Component {
barTintColor="darkslateblue"
itemPositioning="center"
tintColor="white"
translucent={ true }
translucent={true}
unselectedTintColor="black"
unselectedItemTintColor="red">
unselectedItemTintColor="red"
>
<TabBarIOS.Item
badge={ 0 }
badge={0}
badgeColor="red"
icon={{uri: undefined}}
selected={ true }
icon={{ uri: undefined }}
selected={true}
onPress={() => {}}
renderAsOriginal={ true }
selectedIcon={ undefined }
renderAsOriginal={true}
selectedIcon={undefined}
systemIcon="history"
title="Item 1">
</TabBarIOS.Item>
title="Item 1"
/>
</TabBarIOS>
);
}
@@ -337,38 +328,32 @@ class TabBarTest extends React.Component {
class AlertTest extends React.Component {
showAlert() {
Alert.alert(
'Title',
'Message',
"Title",
"Message",
[
{ text: 'First button', onPress: () => {} },
{ text: 'Second button', onPress: () => {} },
{ text: 'Third button', onPress: () => {} }
{ text: "First button", onPress: () => {} },
{ text: "Second button", onPress: () => {} },
{ text: "Third button", onPress: () => {} },
],
{
cancelable: false,
onDismiss: () => {}
onDismiss: () => {},
}
)
);
}
render() {
return (
<Button title='Press me' onPress={this.showAlert}/>
);
return <Button title="Press me" onPress={this.showAlert} />;
}
}
class MaskedViewTest extends React.Component {
render() {
return (
<MaskedView
maskElement={
<View />
}
>
<MaskedView maskElement={<View />}>
<View />
</MaskedView>
)
);
}
}
@@ -378,11 +363,11 @@ const dataSourceAssetCallback1: DataSourceAssetCallback = {
sectionHeaderHasChanged: (h1, h2) => true,
getRowData: (dataBlob, sectionID, rowID) => (sectionID as number) + (rowID as number),
getSectionHeaderData: (dataBlob, sectionID) => sectionID as string,
}
};
const dataSourceAssetCallback2: DataSourceAssetCallback = {}
const dataSourceAssetCallback2: DataSourceAssetCallback = {};
// DeviceEventEmitterStatic
const deviceEventEmitterStatic: DeviceEventEmitterStatic = null;
deviceEventEmitterStatic.addListener('keyboardWillShow', (data) => true);
deviceEventEmitterStatic.addListener('keyboardWillShow', (data) => true, {});
deviceEventEmitterStatic.addListener("keyboardWillShow", data => true);
deviceEventEmitterStatic.addListener("keyboardWillShow", data => true, {});

View File

@@ -1,45 +1,36 @@
import * as React from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import * as React from "react";
import { AppRegistry, StyleSheet, Text, View } from "react-native";
export default class AwesomeProject extends React.Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>To get started, edit index.ios.js</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{"\n"}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF",
},
welcome: {
fontSize: 20,
textAlign: "center",
margin: 10,
},
instructions: {
textAlign: "center",
color: "#333333",
marginBottom: 5,
},
});