Skip to content

Commit

Permalink
fix:修改demo
Browse files Browse the repository at this point in the history
  • Loading branch information
taxue1640 committed Jun 6, 2024
1 parent a051352 commit fd24d06
Show file tree
Hide file tree
Showing 47 changed files with 337 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ControllableComponent = (props: any) => {
onChangeText={(text) => {
setState(text);
}}
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
style={{ height: 40, borderColor: 'gray', borderWidth: 1, fontSize: 16 }}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ControllableComponent = (props:any) => {
<TextInput
value={state}
onChangeText={(text) => setState(text)}
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
style={{ height: 40, borderColor: 'gray', borderWidth: 1, fontSize: 16 }}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function UncontrolledControllableValue(props: any) {
value={state}
onChangeText={(text: string) => setState(text)}
keyboardType='default'
style={{ height: 40, borderColor: 'gray', borderWidth: 1, marginTop: 40, width: 350, marginLeft: 20, marginBottom: 20 }}
style={{ height: 40, borderColor: 'gray', borderWidth: 1, marginTop: 40, width: 350, marginLeft: 20, marginBottom: 20, fontSize: 16}}
/>
<Button
title='Clear'
Expand Down
2 changes: 1 addition & 1 deletion ahooks/Advanced/useEventEmitter/EventEmitter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const InputBox = ({ focus$ }: { focus$: any }) => {
focus$.useSubscription(() => {
inputRef.current.focus();
});
return <TextInput ref={inputRef} placeholder="Enter reply" style={{ width: '100%', padding: 4 }} />;
return <TextInput ref={inputRef} placeholder="Enter reply" style={{ width: '100%', padding: 4, borderWidth: 1, fontSize: 16}} />;
};

export function EventEmitter() {
Expand Down
1 change: 0 additions & 1 deletion ahooks/Dom/index.ts

This file was deleted.

43 changes: 0 additions & 43 deletions ahooks/Dom/useMutationObserver/MutationObserver.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion ahooks/Effect/useAsyncEffect/UseAsyncEffectInterrupt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function UseAsyncEffectInterrupt() {
<View>
<TextInput
value={value}
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
style={{ height: 40, borderColor: 'gray', borderWidth: 1, fontSize: 16 }}
onChangeText={(text) => {
setValue(text);
}}
Expand Down
2 changes: 1 addition & 1 deletion ahooks/Effect/useDebounceEffect/UseDebounceEffect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function UseDebounceEffect() {
value={value}
onChangeText={(text) => setValue(text)}
placeholder="Typed value"
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
style={{ height: 40, borderColor: 'gray', borderWidth: 1, fontSize: 16 }}
/>
<Text style={{ marginTop: 16 }}>
<FlatList
Expand Down
2 changes: 1 addition & 1 deletion ahooks/Effect/useRafInterval/UseRafInterval.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React, { useState } from 'react';
import { useRafInterval } from 'ahooks';
import { View } from 'react-native';
import { View,Text } from 'react-native';

export function UseRafInterval() {
const [count, setCount] = useState(0);
Expand Down
2 changes: 1 addition & 1 deletion ahooks/Effect/useThrottleEffect/UseThrottleEffect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function UseThrottleEffect() {
value={value}
onChangeText={(text) => setValue(text)}
placeholder="Typed value"
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
style={{ height: 40, borderColor: 'gray', borderWidth: 1, fontSize: 16 }}
/>
<Text style={{ marginTop: 16 }}>
<FlatList
Expand Down
8 changes: 4 additions & 4 deletions ahooks/Hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PortalProvider } from '@gorhom/portal';
import {
BasicCancel,
BasicDefault,
BasicDefaultFalse,
BasicLifeCycle,
BasicManualRun,
BasicManualRunAsync,
Expand Down Expand Up @@ -82,7 +83,6 @@ import {
UseUpdate
} from './Effect';

import { MutationObserver } from './Dom'

import {
ChangeControllableValue,
Expand Down Expand Up @@ -114,6 +114,9 @@ function Hooks() {
<Page name="TEST:Request_BasicDefault">
<BasicDefault />
</Page>
<Page name="TEST:Request_BasicDefaultFalse">
<BasicDefaultFalse />
</Page>
<Page name="TEST:Request_BasicLifeCycle">
<BasicLifeCycle />
</Page>
Expand Down Expand Up @@ -333,9 +336,6 @@ function Hooks() {
</View>

<View>
<Page name="DOM:MutationObserver ">
<MutationObserver />
</Page>
<Page name="Advanced:ChangeControllableValue ">
<ChangeControllableValue />
</Page>
Expand Down
2 changes: 1 addition & 1 deletion ahooks/State/useCookieState/CookieState1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function CookieState1() {
value={message}
placeholder="Please enter some words..."
onChange={(e:any) => setMessage(e.target.value)}
style={{ width: 300 }}
style={{ width: 300, borderWidth: 1, fontSize: 16 }}
/>
);
};
Expand Down
2 changes: 1 addition & 1 deletion ahooks/State/useDebounce/Debounce1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function Debounce1(){
value={value}
onChangeText={(text) => setValue(text)}
placeholder="Typed value"
style={{ width: 280, borderWidth: 1, borderColor: 'black', padding: 8 }}
style={{ width: 280, borderWidth: 1, borderColor: 'black', padding: 8, fontSize: 16 }}
/>
<Text style={{ marginTop: 16 }}>DebouncedValue: {debouncedValue}</Text>
</View>
Expand Down
4 changes: 2 additions & 2 deletions ahooks/State/usePrevious/Previous2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function Previous2(){
<Text style={{ marginBottom: 8 }}>previous job: {(previousJob || {}).job}</Text>
<View style={{ marginTop: 8 }}>
<TextInput
style={{ width: 220, borderWidth: 1, borderColor: '#e8e8e8', padding: 8 }}
style={{ width: 220, borderWidth: 1, borderColor: '#e8e8e8', padding: 8, fontSize: 16 }}
value={nameInput}
onChangeText={(text) => setNameInput(text)}
placeholder="new name"
Expand All @@ -68,7 +68,7 @@ export function Previous2(){
</View>
<View style={{ marginTop: 8 }}>
<TextInput
style={{ width: 220, borderWidth: 1, borderColor: '#e8e8e8', padding: 8 }}
style={{ width: 220, borderWidth: 1, borderColor: '#e8e8e8', padding: 8, fontSize: 16 }}
value={jobInput}
onChangeText={(text) => setJobInput(text)}
placeholder="new job"
Expand Down
2 changes: 1 addition & 1 deletion ahooks/State/useThrottle/Throttle1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function Throttle1(){
value={value}
onChangeText={(text) => setValue(text)}
placeholder="Typed value"
style={{ width: 280, borderWidth: 1, borderColor: 'black', padding: 8 }}
style={{ width: 280, borderWidth: 1, borderColor: 'black', padding: 8, fontSize: 16 }}
/>
<Text style={{ marginTop: 16 }}>throttledValue: {throttledValue}</Text>
</View>
Expand Down
1 change: 1 addition & 0 deletions ahooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './useRequest/basic/BasicCancel';
export * from './useRequest/basic/BasicDefault';
export * from './useRequest/basic/BasicDefaultFalse';
export * from './useRequest/basic/BasicLifeCycle';
export * from './useRequest/basic/BasicManualRun';
export * from './useRequest/basic/BasicManualRunAsync';
Expand Down
2 changes: 1 addition & 1 deletion ahooks/scene/useHistoryTravel/HistoryTravel1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function HistoryTravel1(){

return (
<View>
<TextInput value={value || ''} onChangeText={setValue} />
<TextInput value={value || ''} onChangeText={setValue} style={{ borderWidth: 1, fontSize: 16 }} />
<View style={{ marginHorizontal: 8 }}>
<Button
title="back"
Expand Down
4 changes: 3 additions & 1 deletion ahooks/scene/useHistoryTravel/HistoryTravel2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function HistoryTravel2(){
<TextInput
value={step}
onChangeText={setStep}
keyboardType="numeric"
keyboardType="phone-pad"
style={styles.stepInput}
/>
<Button title="Go" onPress={onGo} />
Expand Down Expand Up @@ -102,6 +102,7 @@ const styles = StyleSheet.create({
marginRight: 8,
paddingHorizontal: 10,
height: 40,
fontSize: 16
},
buttonContainer: {
flexDirection: 'row',
Expand All @@ -119,5 +120,6 @@ const styles = StyleSheet.create({
paddingHorizontal: 10,
height: 40,
width: 60,
fontSize: 16
},
});
2 changes: 1 addition & 1 deletion ahooks/scene/useHistoryTravel/HistoryTravel3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function HistoryTravel3(){
<Text>backLength: {backLength}</Text>
<Text>forwardLength: {forwardLength}</Text>
</View>
<TextInput value={value || ''} onChangeText={setValue} />
<TextInput value={value || ''} onChangeText={setValue} style={{ borderWidth: 1, fontSize: 16 }} />
<View
style={{ marginHorizontal: 8 }}>
<Button
Expand Down
29 changes: 18 additions & 11 deletions ahooks/useRequest/basic/BasicCancel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ import React, { useState } from 'react';
import { View, TextInput, Button, Alert, StyleSheet } from 'react-native';
import { useRequest } from 'ahooks';

function editUsername(username: string): Promise<void> {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (Math.random() > 0.5) {
resolve();
} else {
reject(new Error('Failed to modify username'));
}
}, 1000);
});
}


export function BasicCancel() {
function editUsername(username: string): Promise<void> {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (flag) {
resolve();
} else {
reject(new Error('Failed to modify username'));
}
}, 1000);
});
}
const [flag,setFlag] = useState(true)
const [state, setState] = useState('');

const { loading, run, cancel } = useRequest(editUsername, {
Expand Down Expand Up @@ -47,6 +49,10 @@ export function BasicCancel() {
onPress={cancel}
title="Cancel"
/>
<Button
onPress={()=>setFlag(!flag)}
title={String(flag)}
/>
</View>
</View>
);
Expand All @@ -64,6 +70,7 @@ const styles = StyleSheet.create({
borderWidth: 1,
padding: 10,
width: 240,
fontSize: 16,
},
buttonContainer: {
flexDirection: 'row',
Expand Down
4 changes: 0 additions & 4 deletions ahooks/useRequest/basic/BasicDefault.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import Mock from 'mockjs'; // 确保 Mockjs 在 React Native 中可用或寻找
function getUsername(): Promise<string> {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (Math.random() > 0.5) {
resolve(Mock.mock('@name'));
} else {
reject(new Error('Failed to get username'));
}
}, 1000);
});
}
Expand Down
43 changes: 43 additions & 0 deletions ahooks/useRequest/basic/BasicDefaultFalse.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* title: Read username
*
* title.zh-CN: 读取用户名称
*/

import React from 'react';
import { View, Text, ActivityIndicator, StyleSheet } from 'react-native';
import { useRequest } from 'ahooks';
import Mock from 'mockjs'; // 确保 Mockjs 在 React Native 中可用或寻找替代方案

function getUsername(): Promise<string> {
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('Failed to get username'));
}, 1000);
});
}

export function BasicDefaultFalse() {
const { data, error, loading } = useRequest(getUsername);

if (error) {
return <View style={styles.container}><Text>{error.message}</Text></View>;
}
if (loading) {
return (
<View style={styles.container}>
<ActivityIndicator />
<Text>Loading...</Text>
</View>
);
}
return <View style={styles.container}><Text>Username: {data}</Text></View>;
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
Loading

0 comments on commit fd24d06

Please sign in to comment.