* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { ViewProps, ColorValue, HostComponent } from 'react-native';
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
import type {
DirectEventHandler,
WithDefault,
Float,
} from 'react-native/Libraries/Types/CodegenTypes';
import { ProcessedColorValue } from 'react-native/Libraries/StyleSheet/processColor';
export type OnHeaderEventData = Readonly<{
percent: Float;
offset: Float;
headerHeight: Float;
}>;
export type VoidEventData = Readonly<{}>;
type AutoRefresh = Readonly<{
refresh?: boolean;
time?: Float;
}>;
export interface NativeProps extends ViewProps {
overScrollBounce?: WithDefault<boolean, true>;
onRefresh?: DirectEventHandler<VoidEventData>;
onHeaderPulling?: DirectEventHandler<OnHeaderEventData>;
onHeaderReleasing?: DirectEventHandler<OnHeaderEventData>;
onPullDownToRefresh?: DirectEventHandler<VoidEventData>;
onReleaseToRefresh?: DirectEventHandler<VoidEventData>;
onHeaderReleased?: DirectEventHandler<VoidEventData>;
enableRefresh?: WithDefault<boolean, true>;
headerHeight?: Float;
overScrollDrag?: WithDefault<boolean, true>;
pureScroll?: WithDefault<boolean, false>;
dragRate?: WithDefault<Float, 0.5>;
maxDragRate?: WithDefault<Float, 2.0>;
primaryColor?: ProcessedColorValue;
autoRefresh?: AutoRefresh;
}
export default codegenNativeComponent<NativeProps>('SmartRefreshLayout');
type SmartRefreshControlType = HostComponent<NativeProps>;
export interface NativeCommands {
finishRefresh: (
viewRef: React.ElementRef<SmartRefreshControlType>,
delayed: Float,
success: boolean,
) => void;
}
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['finishRefresh'],
});