Add definitions for react-native-read-more-text

This commit is contained in:
Jeff Held
2018-12-18 16:39:18 -06:00
parent 444ae0e622
commit cf27ea6211
4 changed files with 100 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
// Type definitions for react-native-read-more-text 1.0
// Project: https://github.com/expo/react-native-read-more-text
// Definitions by: Jeff Held <https://github.com/solkaz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from "react";
export interface ReadMoreProps {
children: React.ReactNode;
numberOfLines: number;
onReady?: () => void;
renderRevealedFooter: (onPress: () => void) => React.ReactNode;
renderTruncatedFooter: (onPress: () => void) => React.ReactNode;
}
export default class ReadMore extends React.Component<ReadMoreProps> {}

View File

@@ -0,0 +1,65 @@
// Tests taken from Usage at https://github.com/expo/react-native-read-more-text#usage
import * as React from "react";
import { Text, View } from "react-native";
import ReadMore from "react-native-read-more-text";
interface Props {
text: string;
}
declare const styles: any;
declare const Colors: any;
export class DescriptionCard extends React.Component<Props> {
render() {
const { text } = this.props;
return (
<View>
<View style={styles.cardLabel}>
<Text style={styles.cardLabelText}>Description</Text>
</View>
<View style={styles.card}>
<View style={styles.cardBody}>
<ReadMore
numberOfLines={3}
renderTruncatedFooter={this._renderTruncatedFooter}
renderRevealedFooter={this._renderRevealedFooter}
onReady={this._handleTextReady}
>
<Text style={styles.cardText}>{text}</Text>
</ReadMore>
</View>
</View>
</View>
);
}
_renderTruncatedFooter = (handlePress: () => void) => {
return (
<Text
style={{ color: Colors.tintColor, marginTop: 5 }}
onPress={handlePress}
>
Read more
</Text>
);
}
_renderRevealedFooter = (handlePress: () => void) => {
return (
<Text
style={{ color: Colors.tintColor, marginTop: 5 }}
onPress={handlePress}
>
Show less
</Text>
);
}
_handleTextReady = () => {
// ...
}
}

View File

@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"jsx": "react-native",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "react-native-read-more-text-tests.tsx"]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }