-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use RTE
TextView
for timeline text messages, add mention pills to m…
…essages (#1990) * Add `formattedBody` to `TimelineItemTextBasedContent`. This is pre-computed when timeline events are being mapped from the Rust SDK. * Update `HtmlConverterProvider` styles. * Improve `MentionSpan` to add missing `@` or `#` if needed * Replace `HtmlDocument` with the `TextView` based component * Improve extra padding calculation for timestamp by rounding the float offset result instead of truncating it. * Remove composer line height workaround * Use `ElementRichTextEditorStyle` instead of `RichTextEditorDefaults` for the theming * Use slightly different styles for composer and messages (top/bottom line height discrepancies, mostly). * Add `formattedBody` to notice and emote events. --------- Co-authored-by: ElementBot <[email protected]>
- Loading branch information
1 parent
e4a07df
commit 1e86d82
Showing
232 changed files
with
754 additions
and
1,124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Use the RTE library `TextView` to render text events in the timeline. | ||
|
||
Add support for mention pills - with no interaction yet. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
*/ | ||
|
||
plugins { | ||
id("io.element.android-library") | ||
id("io.element.android-compose-library") | ||
} | ||
|
||
android { | ||
|
29 changes: 29 additions & 0 deletions
29
...rc/main/kotlin/io/element/android/features/messages/api/timeline/HtmlConverterProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2023 New Vector 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. | ||
*/ | ||
|
||
package io.element.android.features.messages.api.timeline | ||
|
||
import androidx.compose.runtime.Composable | ||
import io.element.android.libraries.matrix.api.core.UserId | ||
import io.element.android.wysiwyg.utils.HtmlConverter | ||
|
||
interface HtmlConverterProvider { | ||
|
||
@Composable | ||
fun Update(currentUserId: UserId) | ||
|
||
fun provide(): HtmlConverter | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...kotlin/io/element/android/features/messages/impl/timeline/DefaultHtmlConverterProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (c) 2023 New Vector 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. | ||
*/ | ||
|
||
package io.element.android.features.messages.impl.timeline | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.platform.LocalInspectionMode | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import io.element.android.features.messages.api.timeline.HtmlConverterProvider | ||
import io.element.android.libraries.core.bool.orFalse | ||
import io.element.android.libraries.di.SessionScope | ||
import io.element.android.libraries.di.SingleIn | ||
import io.element.android.libraries.matrix.api.core.UserId | ||
import io.element.android.libraries.textcomposer.ElementRichTextEditorStyle | ||
import io.element.android.libraries.textcomposer.mentions.rememberMentionSpanProvider | ||
import io.element.android.wysiwyg.compose.StyledHtmlConverter | ||
import io.element.android.wysiwyg.display.MentionDisplayHandler | ||
import io.element.android.wysiwyg.display.TextDisplay | ||
import io.element.android.wysiwyg.utils.HtmlConverter | ||
import uniffi.wysiwyg_composer.newMentionDetector | ||
import javax.inject.Inject | ||
|
||
@ContributesBinding(SessionScope::class) | ||
@SingleIn(SessionScope::class) | ||
class DefaultHtmlConverterProvider @Inject constructor(): HtmlConverterProvider { | ||
|
||
private val htmlConverter: MutableState<HtmlConverter?> = mutableStateOf(null) | ||
|
||
@Composable | ||
override fun Update(currentUserId: UserId) { | ||
val isInEditMode = LocalInspectionMode.current | ||
val mentionDetector = remember(isInEditMode) { | ||
if (isInEditMode) { null } else { newMentionDetector() } | ||
} | ||
|
||
val editorStyle = ElementRichTextEditorStyle.textStyle() | ||
val mentionSpanProvider = rememberMentionSpanProvider(currentUserId = currentUserId) | ||
|
||
val context = LocalContext.current | ||
|
||
htmlConverter.value = remember(editorStyle, mentionSpanProvider) { | ||
StyledHtmlConverter( | ||
context = context, | ||
mentionDisplayHandler = object : MentionDisplayHandler { | ||
override fun resolveAtRoomMentionDisplay(): TextDisplay { | ||
return TextDisplay.Custom(mentionSpanProvider.getMentionSpanFor(text = "@room", url = "#")) | ||
} | ||
|
||
override fun resolveMentionDisplay(text: String, url: String): TextDisplay { | ||
return TextDisplay.Custom(mentionSpanProvider.getMentionSpanFor(text, url)) | ||
} | ||
}, | ||
isMention = { _, url -> mentionDetector?.isMention(url).orFalse() } | ||
).apply { | ||
configureWith(editorStyle) | ||
} | ||
} | ||
} | ||
|
||
override fun provide(): HtmlConverter { | ||
return htmlConverter.value ?: error("HtmlConverter wasn't instantiated. Make sure to call HtmlConverterProvider.Update() first.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.