Skip to content

Commit 04547f7

Browse files
authored
Merge pull request #990 from wordpress-mobile/release/1.5.9
Release v1.5.9
2 parents a27546b + d5be242 commit 04547f7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,42 @@ When switched, this editor will always add media and horizontal rule after the c
152152
aztecText.addMediaAfterBlocks()
153153
```
154154

155+
### Placeholder API
156+
157+
Aztec now supports placeholders to draw views which are not natively supported by the EditText and Spannable API.
158+
The functionality creates a span in the visual editor and draws an Android view over it.
159+
The view is moved around when the user changes anything in the editor and allows you to draw things like video that can be played inline in the editor.
160+
In order to use the API you have to create an instance of `PlaceholderManager` and initialize it in your `onCreate` call like this:
161+
162+
```kotlin
163+
private lateinit var placeholderManager: PlaceholderManager
164+
override fun onCreate(savedInstanceState: Bundle?) {
165+
placeholderManager = PlaceholderManager(visualEditor, findViewById(R.id.container_frame_layout))
166+
aztec.addPlugin(placeholderManager)
167+
aztec.addOnMediaDeletedListener(placeholderManager)
168+
}
169+
override fun onDestroy() {
170+
placeholderManager.onDestroy()
171+
}
172+
```
173+
174+
You can create a custom `PlaceholderAdapter` to prepare and draw your view.
175+
You can check the sample `ImageWithCaptionAdapter` which draws a simple Android view with an image and a caption.
176+
However, you can implement things like `YouTube` view or `Video` view with playback controls.
177+
Don't forget to register your `PlaceholderAdapter` like this:
178+
179+
```kotlin
180+
placeholderManager.registerAdapter(ImageWithCaptionAdapter())
181+
```
182+
183+
Once you have initialized both the manager and the adapter, you can use the manager methods to insert or remove placeholders.
184+
185+
```kotlin
186+
placeholderManager.insertItem(adapterType, attributes)
187+
placeholderManager.removeItem(predicate)
188+
```
189+
190+
155191
## Code formatting
156192

157193
We use [ktlint](https://github.com/shyiko/ktlint) for Kotlin linting. You can run ktlint using `./gradlew ktlint`, and you can also run `./gradlew ktlintFormat` for auto-formatting. There is no IDEA plugin (like Checkstyle's) at this time.

0 commit comments

Comments
 (0)