Skip to content

Commit

Permalink
share ref with update method (#204)
Browse files Browse the repository at this point in the history
* share ref with update method
  • Loading branch information
arekkubaczkowski committed Jul 14, 2020
1 parent 01342b8 commit 5ceb08b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Check out the [example project](example) for more examples.
- [`minimumTrackImage`](#minimumtrackimage)
- [`thumbImage`](#thumbimage)
- [`trackImage`](#trackimage)
- [`ref`](#ref)

---

Expand Down Expand Up @@ -266,6 +267,16 @@ Assigns a single image for the track. Only static images are supported. The cent
| ---------------------- | -------- | -------- |
| Image.propTypes.source | No | iOS |

---

### `ref`

Reference object.

| Type | Required | Platform |
| ---------------- | -------- | -------- |
| MutableRefObject | No | web |

## Contributing

This project uses [yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/) to handle its internal dependencies.
Expand Down
10 changes: 10 additions & 0 deletions src/js/RNCSliderNativeComponent.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ const RCTSliderWebComponent = React.forwardRef(
}
};

React.useImperativeHandle(
forwardedRef,
() => ({
updateValue: val => {
updateValue(val);
},
}),
[updateValue],
);

return (
<View
ref={containerRef}
Expand Down
9 changes: 9 additions & 0 deletions src/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export interface SliderPropsAndroid extends ReactNative.ViewProps {
thumbTintColor?: string;
}

export interface SliderRef {
updateValue(value: number): void;
}

export interface SliderPropsIOS extends ReactNative.ViewProps {
/**
* Assigns a maximum track image. Only static images are supported.
Expand Down Expand Up @@ -123,6 +127,11 @@ export interface SliderProps extends SliderPropsIOS, SliderPropsAndroid {
* Should be a plural word, as singular units will be handled.
*/
accessibilityIncrements?: Array<string>;

/**
* Reference object.
*/
ref: React.MutableRefObject<SliderRef>;
}

/**
Expand Down

0 comments on commit 5ceb08b

Please sign in to comment.